版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、标分割算法之分岭算法分岭实现原理分岭算法常于标分割研究,其将图像以灰度为参考可视化为种拓扑地貌,灰度等价于海拔低,如果向地貌中的进漫,定程度时丘将被分开成独个体1.1基于降法实现分岭如上图所,假设从给出降落,最终在聚集,不同的被赋予不同颜,然,在不同颜出现汇聚的地,混合颜的位置就可以修建坝,将标分割开1.2基于灌法实现分岭如上图所平图,从各个挖个洞向上灌(灌位置对应局部极值,伴随位上升,不同的相遇时,就可以修建坝具体实现附:opencv官应举例:const int SHED=-1;const int INQUEUE=-2;struct point2D *other position is 0.
2、(32-bit 1 channel img)cvtColor(gray_img, gray_img, COLOR_BGR2GRAY);/res设为输出标记图像for (int i =0; i res.cols; i) p =; /第置为-1p =res.ptrint(Rows);for (int i =1; i Rows; i)/当前res代表标记图像int res_p_pre =res.ptrint (i - 1);int res_p_cur =res.ptrint ();int res_p_next =res.ptrint (i +1);uchar gray_p =gray.ptrucha
3、r ();res_p_cur0 =; res_p_curCols =;/结果图第列和最后列置为-1for (int j =1; j Cols; j)/遍历每列if (res_p_cur 0) res_p_cur =0; /不存在 0 | res_p_next 0| res_p_curj - 1 0 | res_p_curj +1 0)/如果标记当前点为0+左点右点上点0+下点0 intensity =gray_p; /强度置为标记点在原图的灰度if (intensity graylevelnum) /如果于256,保存到每个灰度级对应的容器中,将其视为将要操作的点,暂时灰度值设-2为 queu
4、esintensity.push( i,j ); res_p_cur =; int ind =0;for (; ind graylevelnum; ind)if (!queuesind.empty() break; /找到第个储存灰度级的不为空的容器索引if (ind graylevelnum)/如果于最灰度级int lab, t;while (true)if (queuesind.empty()for (; ind graylevelnum; ind)if (!queuesind.empty() break; /灰度级遍历时也会出现为0的灰度级容器,跳过它找出下个索引point2D cur
5、=queuesind.front();/读取当前种点queuesind.pop();/删除栈顶元素/mark current pixel.获取label值,于标记?t =res.atint(cur.r - 1, cur.c);/此处四邻域与上边记录四邻域点存邻域时保持致t =res.atint(cur.r +1, cur.c);/公共区域修建坝?res.atint(cur.r, cur.c) =lab;/当前种点在结果图像标记为lab/std:cout lab: lab std:endl;if (lab !=)/如果标记不是坝,应继续进长漫将原始标记图中未标记的点压容器进标记/check 4
6、neighbors for unmarked r_ind =cur.r - 1, c_ind =cur.c;/rc表与列if (res.atint(r_ind, c_ind) =0)/未进标记的点t =gray.atuchar (r_ind, c_ind);/std:cout t: t std:endl;queuest.push( r_ind,c_ind );res.atint(r_ind, c_ind) =;ind =ind t ? ind : t;/ind为当前遍历的灰度级加梯度图进改进:Sobel(gray_img, sobel_x, CV_64F, 1, 0, 3
7、);Sobel(gray_img, sobel_y, CV_64F, 0, 1, 3);convertScaleAbs(sobel_x, sobel_x);convertScaleAbs(sobel_y, sobel_y);Mat grad =sobel_x +sobel_y;针对梯度图中的背景点并进操作if (lab !=)/如果标记不是坝,应继续进长漫将原始标记图中未标记的点压容器进标记t =gray.atuchar (r_ind, c_ind);/std:cout t: t std:endl;if (t != 0) queuest.push( r_ind,c_ind );res.atin
8、t(r_ind, c_ind) =;ind =ind t ? ind : t;/ind为当前遍历的灰度级t =gray.atuchar (r_ind, c_ind);/std:cout t: t std:endl;if (t != 0) queuest.push( r_ind,c_ind );res.atint(r_ind, c_ind) =;ind =ind t ? ind : t;/ind为当前遍历的灰度级t =gray.atuchar (r_ind, c_ind);/std:cout t: t std:endl;if (t != 0) queuest.push( r_ind,c_ind
9、);res.atint(r_ind, c_ind) =;ind =ind t ? ind : t;/ind为当前遍历的灰度级t =gray.atuchar (r_ind, c_ind);/std:cout t: t std:endl;if (t != 0) queuest.push( r_ind,c_ind );res.atint(r_ind, c_ind) =;ind =ind t ? ind : t;/ind为当前遍历的灰度级主程序:tw or SPACE - run watershed segmentation algorithmntt(before running it, *rough
10、ly* mark the areas to segment on the image)nt (before that, roughly outline several markers on the image)n ;else if (event =EVENT_MOUSEMOVE&(flags &EVENT_FLAG_LBUTTON)line(markerMask, prevPt, pt, Scalar(12,234,12), 40, 8, 0);prevPt =pt;imshow(image, img);int main(int argc, char*argv)cv:CommandLinePa
11、rser parser(argc, argv, help h | | input | fruits.jpg | );if (parser.has(help)help(argv);return 0;/string filename = samples:findFile(parser.get(input);Mat img0 =imread(.), imgGray;if (img0.empty()cout Couldnt open image ;help(argv);return 0;help(argv);/img0 = img0(Rect(1000, 1000, 800, 800);namedWindow(image, WINDOW_NORMAL);img0.copyTo(img);cvtColor(img, markerMask, COLOR_BGR2GRAY);cvtColor(markerMask,
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年吉林省延吉市高二生物下册期末考试模拟卷(达标题)附答案
- 2026年湖南省吉首市高二生物下册期末考试测试卷附完整答案【有一套】
- 2026年河北省霸州市高二生物下册期末考试检测卷及完整答案(历年真题)
- 2025年江苏省溧阳市高二生物下册期末考试模拟卷及参考答案【新】
- 2026年湖南省武冈市高二生物下册期末考试试卷含答案(A卷)
- 2026年辽宁省大石桥市高二生物下册期末考试模拟卷附答案(精练)
- 2026年陕西省韩城市高二生物下册期末考试测试卷含答案(完整版)
- 2026年江西省高安市高二生物下册期末考试检测卷含答案(预热题)
- 2025年山东省蓬莱市高二生物下册期末考试试卷带答案(精练)
- 村镇三资基础业务培训
- 2025年湿地生态旅游行业分析报告及未来发展趋势预测
- 2024甘肃畜牧工程职业技术学院辅导员招聘笔试真题及答案
- 金属文物修复师理念考核试卷及答案
- 林业生产安全培训课件
- 污水提升泵基础知识培训课件
- 2025年矫直工考试题库
- 开票加几个点测算表excel公式设置自动计算
- 广东省珠海市2024-2025学年七年级下学期期末数学试卷(含答案)
- 2025年新能源与可再生资源专业实践能力考核试题及答案
- 安徽省水利水电工程施工招标文件示范文本(2025年版)
- 电气火灾试题及答案
评论
0/150
提交评论