图像细化算法大全
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
图像细化算法大全(1)
#include "StdAfx.h"
#include
#include
void beforethin(unsigned char *ip, unsigned char *jp,
unsigned long lx, unsigned long ly)
{
unsigned long i,j;
for(i=0; i { for(j=0; j { //这里要视前景是白点还是黑点而定,可以改动 //如果前景是白点,就是这样;反之反过来 if(ip[i*lx+j]>0) jp[i*lx+j]=1; else jp[i*lx+j]=0; } } } ///////////////////////////////////////////////////////////////////////// //Hilditch细化算法 //功能:对图象进行细化 //参数:image:代表图象的一维数组 // lx:图象宽度 // ly:图象高度 // 无返回值 void ThinnerHilditch(void *image, unsigned long lx, unsigned long ly) { char *f, *g; char n[10]; unsigned int counter; short k, shori, xx, nrn; unsigned long i, j; long kk, kk11, kk12, kk13, kk21, kk22, kk23, kk31, kk32, kk33, size; size = (long)lx * (long)ly; g = (char *)malloc(size); if(g == NULL) { printf("error in allocating memory!\n"); return; } f = (char *)image; for(i=0; i { for(j=0; j { kk=i*ly+j; if(f[kk]!=0) { f[kk]=1; g[kk]=f[kk]; } } } counter = 1; do { printf("%4d*",counter); counter++; shori = 0; for(i=0; i { for(j=0; j kk = i*ly+j; if(f[kk]<0) f[kk] = 0; g[kk]= f[kk]; } } for(i=1; i { for(j=1; j kk=i*ly+j; if(f[kk]!=1) continue; kk11 = (i-1)*ly+j-1; kk12 = kk11 + 1; kk13 = kk12 + 1; kk21 = i*ly+j-1; kk22 = kk21 + 1; kk23 = kk22 + 1; kk31 = (i+1)*ly+j-1; kk32 = kk31 + 1; kk33 = kk32 + 1; if((g[kk12]&&g[kk21]&&g[kk23]&&g[kk32])!=0) continue; nrn = g[kk11] + g[kk12] + g[kk13] + g[kk21] + g[kk23] + g[kk31] + g[kk32] + g[kk33]; if(nrn <= 1) { f[kk22] = 2; continue; } n[4] = f[kk11]; n[3] = f[kk12]; n[2] = f[kk13]; n[5] = f[kk21]; n[1] = f[kk23]; n[6] = f[kk31]; n[7] = f[kk32]; n[8] = f[kk33]; n[9] = n[1]; xx = 0; for(k=1; k<8; k=k+2) { if((!n[k])&&(n[k+1]||n[k+2])) xx++; } if(xx!=1) { f[kk22] = 2; continue; if(f[kk12] == -1) { f[kk12] = 0; n[3] = 0; xx = 0; for(k=1; k<8; k=k+2) { if((!n[k])&&(n[k+1]||n[k+2])) xx++; } if(xx != 1) { f[kk12] = -1; continue; } f[kk12] = -1; n[3] = -1; } if(f[kk21]!=-1) { f[kk22] = -1; shori = 1; continue; } f[kk21] = 0; n[5] = 0; xx = 0; for(k=1; k<8; k=k+2) { if((!n[k])&&(n[k+1]||n[k+2])) { xx++; } } if(xx == 1)