区域生长算法代码_第1页
区域生长算法代码_第2页
区域生长算法代码_第3页
区域生长算法代码_第4页
区域生长算法代码_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、区域生长算法代码函数名称:FillDibEx函数功能:区域生长/入口参数:SrcImg : TGraylmg -原图象/ Seed : TPoint -起始种子坐标/ DestImg : TGrayImg -目的图象返回参数:Boolean-成功返回True,否则返回False/= = = = = = = = = = = = = = = = = =/function FillDibEx(SrcImg : TGrayImg; Seed : TPoint; var DestImg : TGrayImg): Boolean;vari, j : Integer;Seeds : array of TPo

2、int;种子堆栈StackPoint : Integer;堆栈指针iCurrentPixelx, iCurrentPixely : Integer; / 当前象素位置pixel : Byte;begin初始化种子trySetLength(Seeds, SrcImg.Width * SrcImg.Height);exceptResult := False;Exit;end;Seeds1.Y := Seed.Y;Seeds1.X := Seed.X;StackPoint := 1;While (StackPoint 0) dobegin取出种子iCurrentPixelx := SeedsStac

3、kPoint.X;iCurrentPixely := SeedsStackPoint.Y;/退栈Dec(StackPoint);pixel := SrcImg.ImgiCurrentPixely, iCurrentPixelx;不是二值图象if (pixel 255) and (pixel 0) and (pixel 128) thenbeginResult := False;Exit;end;将当前的点涂黑SrcImg.ImgiCurrentPixely, iCurrentPixelx := 128;判断左边的点,如果为白,则压入堆栈注意防止越界if iCurrentPixelx 0 the

4、nbeginpixel := SrcImg.ImgiCurrentPixely, iCurrentPixelx - 1;if pixel = 255 thenbeginInc(StackPoint);SeedsStackPoint.Y := iCurrentPixely;SeedsStackPoint.X := iCurrentPixelx - 1;end;if (pixel 0) and (pixel 128) and (pixel 255) thenbeginResult := False;Exit;end;end;判断下面的点,如果为白,压入堆栈注意防止越界if (iCurrentPix

5、ely SrcImg.Height - 1) thenbeginpixel := SrcImg.ImgiCurrentPixely + 1, iCurrentPixelx;if pixel = 255 thenbeginInc(StackPoint);SeedsStackPoint.Y := iCurrentPixely + 1;SeedsStackPoint.X := iCurrentPixelx;end;if (pixel 0) and (pixel 128) and (pixel 255) thenbeginResult := False;Exit;end;end;判断右边的点,如果为白

6、,则压入堆栈注意防止越界if iCurrentPixelx SrcImg.Width - 1 thenbeginpixel := SrcImg.ImgiCurrentPixely, iCurrentPixelx + 1;if pixel = 255 thenbeginInc(StackPoint);SeedsStackPoint.Y := iCurrentPixely;SeedsStackPoint.X := iCurrentPixelx + 1;end;if (pixel 0) and (pixel 128) and (pixel 255) thenbeginResult := False;

7、Exit;end;end;判断上面的点,如果为白,压入堆栈注意防止越界if (iCurrentPixely 0) thenbeginpixel := SrcImg.ImgiCurrentPixely - 1, iCurrentPixelx;if pixel = 255 thenbeginInc(StackPoint);SeedsStackPoint.Y := iCurrentPixely - 1;SeedsStackPoint.X := iCurrentPixelx;end;if (pixel 0) and (pixel 128) and (pixel 255) thenbeginResult

8、 := False;Exit;end;end;end;保存填充区域,恢复原始图象if not SetImgArray(SrcImg.Width, SrcImg.Height, DestImg) then beginResult := False;Exit;end;for i := 0 to SrcImg.Height - 1 dofor j := 0 to SrcImg.Width - 1 dobeginDestImg.Imgi, j := SrcImg.Imgi, j;if SrcImg.Imgi, j = 128 thenbegin/ SrcImg.Imgi,j := 255;DestIm

9、g.Imgi,j := 0;end;end;Result := True;end;#include #include #define IWidth 8#define IHeight 8void RegionGrow( unsigned char * pUnchInput, int nThreshold,int *pflag,int &b,int start_x,int start_y,int startx,int starty,int endx,int endy)(int nDx=-1,0,1,1,1,0,-1,-1;int nDy=-1,-1,-1,0,1,1,1,0;int nStart

10、;int nEnd ;int nSeedX, nSeedY;/设置种子点为图像的中心nSeedX = start_x;nSeedY = start_y;pflagnSeedY*IWidth+nSeedX = b;初始化nStart = 0 ;nEnd =0 ;int * pnGrowQueX ;int * pnGrowQueY ;/分配空间pnGrowQueX = new int IWidth*IHeight;pnGrowQueY = new int IWidth*IHeight;pnGrowQueXnEnd = nSeedX;pnGrowQueYnEnd = nSeedY;int nCurr

11、X ;int nCurrY ;int k ;int xx;int yy;_/当前种子点的坐标nCurrX = pnGrowQueXnStart;nCurrY = pnGrowQueYnStart;/对当前点的8邻域进行遍历for (k=0; k8; k+)xx = nCurrX+nDxk;yy = nCurrY+nDyk;if (xx =startx) & (yy=starty)& (pflagyy*IWidth+xx=0) & abs(pUnchInputyy*IWidth+xx pUnchInputnCurrY*IWidth+nCurrX)nThreshold )/堆栈的尾部指针后移一位n

12、End+;/象素(xx,yy)压入栈pnGrowQueXnEnd = xx;pnGrowQueYnEnd = yy;pflagyy*IWidth+xx = b ;b+;/释放内存delete pnGrowQueX;delete pnGrowQueY;pnGrowQueX = NULL ;pnGrowQueY = NULL ;void Oppe_Radiate_grayEx5(BYTE *bits,int startx,int starty,int endx,int endy)wiWid,h,Hevolatile int i,j;int m=1;for(i=0;iIWidth*IHeight;i

13、+)flagi=0;for(j=(starty);jendy;j+);i+)if(flagj*IWidth+i=0)RegionGrow(bits,2,flag,m,i,j,startx,starty,endx,endy);for(j=0;jIHeight;j+)for(i=0;iIWidth;i+)coutflagj*IWidth+i;一long *sum=new long m-1;int *count=new int m-1;)sumi=0;counti=0;for(j=(starty);jendy;j+)gcountflagj*IWidth+i-1+;or(j_)sumflagj*IWidth+i-1+=bitsj*IWidth+i;+)_;or(j=(s+)bitsj*IWidth+i=sumflagj*IWidth+i-1;dfdelete sum;delete flag;()BYTE bit64=( 50,50,50,50,50,50,50,50,50, 2, 1, 1,2, 1, 1,50,50, 1,5, 4, 5, 5, 1,50,50, 2, 5, 8, 9, 6, 2,50,50, 1,6, 9, 8, 6

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论