版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- ISO 4392020 钢和铸铁.硅含量的测定.重量法标准立项发展报告
- ISO 24409-12020 船舶和船舶技术 - 船上安全标志 安全标志 安全通知和安全标志的设计 定位和使用 - 第1部分设计原则标准立项发展报告
- 技术合作地基基础工程协议
- 2026年度宴会服务转包协议
- 公共停车场容量测算方案
- 航天境外技术服务合同
- 2026年济南驾校摩托考试试题及答案
- 医院桌面云方案
- 装饰工程墙面瓷砖铺贴实施方案
- 制造业企业数字化转型与工业互联网平台建设方案
- 陶瓷挤出成型工作业指导书
- 消毒供应质控新标
- 医院保洁消防知识培训课件
- 【高考真题】陕西、山西、宁夏、青海2025年高考历史真题(含答案)
- 2025年4月自考06091薪酬管理试题及答案
- 高效团队建设的KPI管理
- 中建建筑工程退场协议书
- 车间处罚制度管理制度
- 2025年江西省上饶市广丰区行政服务中心工作人员招聘22人历年高频重点提升(共500题)附带答案详解
- 加油站施工施工组织设计方案
- 吉林大学《数字逻辑》2021-2022学年期末试卷
评论
0/150
提交评论