【图像检测】基于区域生长算法实现对焊接孔隙检测matlab代码
【图像检测】基于区域生长算法实现对焊接孔隙检测matlab代码
TT_Matlab
每天分享一点Matlab资料,一起成长进步。需要定制程序添加qq1575304183
1 简介
本文采用区域生长算法对焊缝缺陷进行有效分割.该算法沿承传统区域生长算法的思想,主要依据边缘灰度突变的信息,在焊缝区域,先定位出所有可能的种子点并确定行方向上缺陷的边缘位置,再取对应处的像素灰度均值作为灰度阈值,最后从种子点开始并以不大于灰度阈值为判定准则进行生长.实验结果表明,该算法几乎能分割出焊缝中全部缺陷,并能使缺陷形状保留完整,这对后续缺陷的分类识别意义重大.
2 完整代码
clear all, close all, clc f = imread(’defective_weld.tif’); imshow(f), title(’原始图象’) figure, [counts,x] = imhist(f); bar(x,counts), title(’原始图象的直方图’) S = 255; T = 65; [g, NR, SI, TI] = regiongrow(f, S, T); figure, imshow(SI), title(’种子点图象’) figure, imshow(TI), title(’阈值测试后的图象’) figure, imshow(g), title(’8连通性分析后的图象’) bw = edge(g, ’canny’); figure, imshow(bw), title(’边缘图象’) ff = f; ff(bw) = 0; figure, imshow(ff), title(’叠加图象’)
function [g, NR, SI, TI] = regiongrow(f, S, T) %REGIONGROW Perform segmentation by region growing. % [G, NR, SI, TI] = REGIONGROW(F, SR, T). S can be an array (the % same size as F) with a 1 at the coordinates of every seed point % and 0s elsewhere. S can also be a single seed value. Similarly, % T can be an array (the same size as F) containing a threshold % value for each pixel in F. T can also be a scalar, in which % case it becomes a global threshold. % % On the output, G is the result of region growing, with each % region labeled by a different integer, NR is the number of % regions, SI is the final seed image used by the algorithm, and TI % is the image consisting of the pixels in F that satisfied the % threshold test. % Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins % Digital Image Processing Using MATLAB, Prentice-Hall, 2004 % $Revision: 1.4 $ $Date: 2003/10/26 22:35:37 $ f = double(f); % If S is a scalar, obtain the seed image. if numel(S) == 1 SI = f == S; S1 = S; else % S is an array. Eliminate duplicate, connected seed locations % to reduce the number of loop executions in the following % sections of code. SI = bwmorph(S, ’shrink’, Inf); J = find(SI); S1 = f(J); % Array of seed values. end TI = false(size(f)); for K = 1:length(S1) seedvalue = S1(K); S = abs(f - seedvalue) <= T; TI = TI | S; end % Use function imreconstruct with SI as the marker image to % obtain the regions corresponding to each seed in S. Function % bwlabel assigns a different integer to each connected region. [g, NR] = bwlabel(imreconstruct(SI, TI));
3 仿真结果
4 参考文献
[1]孙太生等. "基于改进区域生长算法的焊缝图像分割." 现代焊接 2(2012):2.
部分理论引用网络文献,若有侵权联系博主删除。
微信扫一扫赞赏作者 赞赏
发送给作者
人赞赏
长按二维码向我转账
受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。
-
Origin(Pro):学习版的窗口限制【数据绘图】 2020-08-07
-
如何卸载Aspen Plus并再重新安装,这篇文章告诉你! 2020-05-29
-
AutoCAD 保存时出现错误:“此图形中的一个或多个对象无法保存为指定格式”怎么办? 2020-08-03
-
OriginPro:学习版申请及过期激活方法【数据绘图】 2020-08-06
-
CAD视口的边框线看不到也选不中是怎么回事,怎么解决? 2020-06-04
-
教程 | Origin从DSC计算焓和比热容 2020-08-31
-
如何评价拟合效果-Origin(Pro)数据拟合系列教程【数据绘图】 2020-08-06
-
Aspen Plus安装过程中RMS License证书安装失败的解决方法,亲测有效! 2021-10-15
-
CAD外部参照无法绑定怎么办? 2020-06-03
-
CAD中如何将布局连带视口中的内容复制到另一张图中? 2020-07-03