纯C语言实现图像处理?
哪位大哥知道如何用纯C语言(不能用TurboC,windowsAPI和MFC)对BMP图像实行二值化处理,最好有源代码,非常感谢!!好的话我肯定追加分数!!!...
哪位大哥知道如何用纯C语言(不能用Turbo C ,windows API 和 MFC)对BMP图像实行二值化处理,最好有源代码,非常感谢!!
好的话我肯定追加分数!!! 展开
好的话我肯定追加分数!!! 展开
4个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define ONE 255
#define ZERO 0
/*
typedef struct tagBITMAPFILEHEADER { // bmfh
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BITMAPFILEHEADER;
typedef struct tagBITMAPINFOHEADER{ // bmih
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER;
*/
void main (int argc,char *argv[])
{
FILE *fi,*fo;//I/O file
char fin[80],fon[80];//I/O file name
unsigned char **ri,**ro;
unsigned char buff;
long w,h;
int t;
int i,j;
if(argc<3)
{
printf("orginfile name:");
scanf("%s",fin);
printf("resultfile name:");
scanf("%s",fon);
}else{
sscanf(argv[1],"%s",fin);
sscanf(argv[2],"%s",fon);
}
if(argc==4)
sscanf(argv[4],"%d",&t);
else{
printf("theshold [0,255]:");
scanf("%d",&t);
}
if (((fi=fopen(fin,"rb"))==NULL)||((fo=fopen(fon,"wb"))==NULL))
{
puts("\nfile open failed");
return;
}
fseek(fi,18L,SEEK_SET);
fread(&w,sizeof(long),1,fi);
fread(&h,sizeof(long),1,fi);
fseek(fi,0L,SEEK_SET);
ri=(unsigned char **)malloc(sizeof(unsigned *)*h);
for (i=0;i<h;i++)
*(ri+i)=(unsigned char *)malloc(sizeof(unsigned)*w);
ro=(unsigned char **)malloc(sizeof(unsigned *)*h);
for (i=0;i<h;i++)
*(ro+i)=(unsigned char *)malloc(sizeof(unsigned)*w);
//分配失败后果自负!
for (i=0;i<32;i++){
fread(&buff,sizeof(buff),1,fi);
fwrite(&buff,sizeof(buff),1,fo);}
for (i=0;i<h;i++)
for (j=0;j<w;j++)
fread(*(ri+i)+j,sizeof(unsigned char),1,fi);
for (i=0;i<h;i++)
for (j=0;j<w;j++)
*(*(ro+i)+j)=((*(*(ri+i)+j)<=t)?ZERO:ONE);
for (i=0;i<h;i++)
for (j=0;j<w;j++)
fwrite(*(ro+i)+j,sizeof(unsigned char),1,fo);
fclose(fo);
}
#include <stdlib.h>
#include <conio.h>
#define ONE 255
#define ZERO 0
/*
typedef struct tagBITMAPFILEHEADER { // bmfh
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BITMAPFILEHEADER;
typedef struct tagBITMAPINFOHEADER{ // bmih
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER;
*/
void main (int argc,char *argv[])
{
FILE *fi,*fo;//I/O file
char fin[80],fon[80];//I/O file name
unsigned char **ri,**ro;
unsigned char buff;
long w,h;
int t;
int i,j;
if(argc<3)
{
printf("orginfile name:");
scanf("%s",fin);
printf("resultfile name:");
scanf("%s",fon);
}else{
sscanf(argv[1],"%s",fin);
sscanf(argv[2],"%s",fon);
}
if(argc==4)
sscanf(argv[4],"%d",&t);
else{
printf("theshold [0,255]:");
scanf("%d",&t);
}
if (((fi=fopen(fin,"rb"))==NULL)||((fo=fopen(fon,"wb"))==NULL))
{
puts("\nfile open failed");
return;
}
fseek(fi,18L,SEEK_SET);
fread(&w,sizeof(long),1,fi);
fread(&h,sizeof(long),1,fi);
fseek(fi,0L,SEEK_SET);
ri=(unsigned char **)malloc(sizeof(unsigned *)*h);
for (i=0;i<h;i++)
*(ri+i)=(unsigned char *)malloc(sizeof(unsigned)*w);
ro=(unsigned char **)malloc(sizeof(unsigned *)*h);
for (i=0;i<h;i++)
*(ro+i)=(unsigned char *)malloc(sizeof(unsigned)*w);
//分配失败后果自负!
for (i=0;i<32;i++){
fread(&buff,sizeof(buff),1,fi);
fwrite(&buff,sizeof(buff),1,fo);}
for (i=0;i<h;i++)
for (j=0;j<w;j++)
fread(*(ri+i)+j,sizeof(unsigned char),1,fi);
for (i=0;i<h;i++)
for (j=0;j<w;j++)
*(*(ro+i)+j)=((*(*(ri+i)+j)<=t)?ZERO:ONE);
for (i=0;i<h;i++)
for (j=0;j<w;j++)
fwrite(*(ro+i)+j,sizeof(unsigned char),1,fo);
fclose(fo);
}
东莞大凡
2024-08-07 广告
2024-08-07 广告
OpenCV标定板是东莞市大凡光学科技有限公司在相机标定中常用的工具。它通常由黑白格点按一定规则排列在平面上组成,如棋盘格或圆形格等。在相机标定时,将标定板置于不同位置和姿态下拍摄图像,利用OpenCV库中的函数检测标定板上的角点或圆心,进...
点击进入详情页
本回答由东莞大凡提供
2018-03-02
展开全部
这个不难吧?虽然我不用c,可是说下怎么做,首先打开一个BMP文件,然后按照bmp格式解析到一个数组中,接着进行二值化(这个有很多方法),最后将数组中的数据写入一个新的BMP文件就可以了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include
<stdio.h>
#include
<stdlib.h>
#include
<conio.h>
#define
ONE
255
#define
ZERO
0
/*
typedef
struct
tagBITMAPFILEHEADER
{
//
bmfh
WORD
bfType;
DWORD
bfSize;
WORD
bfReserved1;
WORD
bfReserved2;
DWORD
bfOffBits;
}
BITMAPFILEHEADER;
typedef
struct
tagBITMAPINFOHEADER{
//
bmih
DWORD
biSize;
LONG
biWidth;
LONG
biHeight;
WORD
biPlanes;
WORD
biBitCount
DWORD
biCompression;
DWORD
biSizeImage;
LONG
biXPelsPerMeter;
LONG
biYPelsPerMeter;
DWORD
biClrUsed;
DWORD
biClrImportant;
}
BITMAPINFOHEADER;
*/
void
main
(int
argc,char
*argv[])
{
FILE
*fi,*fo;//I/O
file
char
fin[80],fon[80];//I/O
file
name
unsigned
char
**ri,**ro;
unsigned
char
buff;
long
w,h;
int
t;
int
i,j;
if(argc<3)
{
printf("orginfile
name:");
scanf("%s",fin);
printf("resultfile
name:");
scanf("%s",fon);
}else{
sscanf(argv[1],"%s",fin);
sscanf(argv[2],"%s",fon);
}
if(argc==4)
sscanf(argv[4],"%d",&t);
else{
printf("theshold
[0,255]:");
scanf("%d",&t);
}
if
(((fi=fopen(fin,"rb"))==NULL)||((fo=fopen(fon,"wb"))==NULL))
{
puts("\nfile
open
failed");
return;
}
fseek(fi,18L,SEEK_SET);
fread(&w,sizeof(long),1,fi);
fread(&h,sizeof(long),1,fi);
fseek(fi,0L,SEEK_SET);
ri=(unsigned
char
**)malloc(sizeof(unsigned
*)*h);
for
(i=0;i<h;i++)
*(ri+i)=(unsigned
char
*)malloc(sizeof(unsigned)*w);
ro=(unsigned
char
**)malloc(sizeof(unsigned
*)*h);
for
(i=0;i<h;i++)
*(ro+i)=(unsigned
char
*)malloc(sizeof(unsigned)*w);
//分配失败后果自负!
for
(i=0;i<32;i++){
fread(&buff,sizeof(buff),1,fi);
fwrite(&buff,sizeof(buff),1,fo);}
for
(i=0;i<h;i++)
for
(j=0;j<w;j++)
fread(*(ri+i)+j,sizeof(unsigned
char),1,fi);
for
(i=0;i<h;i++)
for
(j=0;j<w;j++)
*(*(ro+i)+j)=((*(*(ri+i)+j)<=t)?ZERO:ONE);
for
(i=0;i<h;i++)
for
(j=0;j<w;j++)
fwrite(*(ro+i)+j,sizeof(unsigned
char),1,fo);
fclose(fo);
}
<stdio.h>
#include
<stdlib.h>
#include
<conio.h>
#define
ONE
255
#define
ZERO
0
/*
typedef
struct
tagBITMAPFILEHEADER
{
//
bmfh
WORD
bfType;
DWORD
bfSize;
WORD
bfReserved1;
WORD
bfReserved2;
DWORD
bfOffBits;
}
BITMAPFILEHEADER;
typedef
struct
tagBITMAPINFOHEADER{
//
bmih
DWORD
biSize;
LONG
biWidth;
LONG
biHeight;
WORD
biPlanes;
WORD
biBitCount
DWORD
biCompression;
DWORD
biSizeImage;
LONG
biXPelsPerMeter;
LONG
biYPelsPerMeter;
DWORD
biClrUsed;
DWORD
biClrImportant;
}
BITMAPINFOHEADER;
*/
void
main
(int
argc,char
*argv[])
{
FILE
*fi,*fo;//I/O
file
char
fin[80],fon[80];//I/O
file
name
unsigned
char
**ri,**ro;
unsigned
char
buff;
long
w,h;
int
t;
int
i,j;
if(argc<3)
{
printf("orginfile
name:");
scanf("%s",fin);
printf("resultfile
name:");
scanf("%s",fon);
}else{
sscanf(argv[1],"%s",fin);
sscanf(argv[2],"%s",fon);
}
if(argc==4)
sscanf(argv[4],"%d",&t);
else{
printf("theshold
[0,255]:");
scanf("%d",&t);
}
if
(((fi=fopen(fin,"rb"))==NULL)||((fo=fopen(fon,"wb"))==NULL))
{
puts("\nfile
open
failed");
return;
}
fseek(fi,18L,SEEK_SET);
fread(&w,sizeof(long),1,fi);
fread(&h,sizeof(long),1,fi);
fseek(fi,0L,SEEK_SET);
ri=(unsigned
char
**)malloc(sizeof(unsigned
*)*h);
for
(i=0;i<h;i++)
*(ri+i)=(unsigned
char
*)malloc(sizeof(unsigned)*w);
ro=(unsigned
char
**)malloc(sizeof(unsigned
*)*h);
for
(i=0;i<h;i++)
*(ro+i)=(unsigned
char
*)malloc(sizeof(unsigned)*w);
//分配失败后果自负!
for
(i=0;i<32;i++){
fread(&buff,sizeof(buff),1,fi);
fwrite(&buff,sizeof(buff),1,fo);}
for
(i=0;i<h;i++)
for
(j=0;j<w;j++)
fread(*(ri+i)+j,sizeof(unsigned
char),1,fi);
for
(i=0;i<h;i++)
for
(j=0;j<w;j++)
*(*(ro+i)+j)=((*(*(ri+i)+j)<=t)?ZERO:ONE);
for
(i=0;i<h;i++)
for
(j=0;j<w;j++)
fwrite(*(ro+i)+j,sizeof(unsigned
char),1,fo);
fclose(fo);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我建议你看一下《c语言编程宝典》这本电子书。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询