纯c语言怎么把存放在二维数组的二值化图像去除较小的连通域? - 爱问答

(爱问答)

纯c语言怎么把存放在二维数组的二值化图像去除较小的连通域?

#include <stdio.h>#include <stdlib.h>#include <conio.h>#define ONE 255#define ZERO 0/*typedef struct tagBITMAPFILEHEADER { // bmfhword bfType;Dword bfSize;WORD bfReserved1;WORD bfReserved2;DWORD bfOffBits;} BITMAPFILEHEADER;typedef struct tagBITMAPINFOHEADER{ // bmihDWORD biSize;LONG biWidth;LONG biHeight;WORD biPlanes;WORD biBitCountDWORD biCompression;DWORD biSizeImage;LONG biXPelsPerMeter;LONG biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant;} BITMAPINFOHEADER;*/void main (int argc,char *argv[]){FILE *fi,*fo;//I/O filechar fin[80],fon[80];//I/O file nameunsigned 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(" file 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语言

下一篇:c语言编程用在32板子上,编程输出一串字符怎么变

上一篇:求大神帮忙解决一下,steamPC版绝地求生加载完反作弊(BE)后,就弹出这个界面,重启也不行。

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?