//************************************************************************** //Thinner.cpp //细化算法实现文件 //************************************************************************** //#include "StdAfx.h" #include #include #include "Thinner.h" #include //将图图像反色 void beforethin(unsigned char *ip, unsigned char *jp, unsigned long lx, unsigned long ly){ //void beforethin(char *ip, char *jp, unsigned long lx, unsigned long ly) unsigned long i,j; for(i=0; i0) jp[i*lx+j]=0; else jp[i*lx+j]=255; } } } ///////////////////////////////////////////////////////////////////////// //Rosenfeld细化算法 //功能:对图象进行细化 //参数:image:代表图象的一维数组 // lx:图象宽度 // ly:图象高度 // 无返回值 void ThinnerRosenfeld(void *image, unsigned long lx, unsigned long ly){ char *f, *g; char n[10]; char a[5] = {0, -1, 1, 0, 0}; char b[5] = {0, 0, 0, 1, -1}; char nrnd, cond, n48, n26, n24, n46, n68, n82, n123, n345, n567, n781; short k, shori; unsigned long i, j; long ii, jj, kk, kk1, kk2, kk3, size; size = (long)lx * (long)ly; g = (char *)malloc(size); if(g==NULL){ printf("error in alocating mmeory!\n"); return; } f = (char *)image; for(kk=0l; kk0){ if(!cond) continue; g[kk] = 0; shori = 1; continue; } if(n[6]==1 && n48==0 && n123>0){ if(!cond) continue; g[kk] = 0; shori = 1; continue; } if(n[8]==1 && n26==0 && n345>0){ if(!cond) continue; g[kk] = 0; shori = 1; continue; } if(n[4]==1 && n26==0 && n781>0){ if(!cond) continue; g[kk] = 0; shori = 1; continue; } if(n[5]==1 && n46==0){ if(!cond) continue; g[kk] = 0; shori = 1; continue; } if(n[7]==1 && n68==0){ if(!cond) continue; g[kk] = 0; shori = 1; continue; } if(n[1]==1 && n82==0){ if(!cond) continue; g[kk] = 0; shori = 1; continue; } if(n[3]==1 && n24==0){ if(!cond) continue; g[kk] = 0; shori = 1; continue; } cond = 1; if(!cond) continue; g[kk] = 0; shori = 1; } } for(i=0; i