【圖像檢測】基于區(qū)域生長算法實(shí)現(xiàn)對焊接孔隙檢測matlab代碼
【圖像檢測】基于區(qū)域生長算法實(shí)現(xiàn)對焊接孔隙檢測matlab代碼
TT_Matlab
每天分享一點(diǎn)Matlab資料,一起成長進(jìn)步。需要定制程序添加qq1575304183
1 簡介
本文采用區(qū)域生長算法對焊縫缺陷進(jìn)行有效分割.該算法沿承傳統(tǒng)區(qū)域生長算法的思想,主要依據(jù)邊緣灰度突變的信息,在焊縫區(qū)域,先定位出所有可能的種子點(diǎn)并確定行方向上缺陷的邊緣位置,再取對應(yīng)處的像素灰度均值作為灰度閾值,最后從種子點(diǎn)開始并以不大于灰度閾值為判定準(zhǔn)則進(jìn)行生長.實(shí)驗(yàn)結(jié)果表明,該算法幾乎能分割出焊縫中全部缺陷,并能使缺陷形狀保留完整,這對后續(xù)缺陷的分類識別意義重大.
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(’種子點(diǎn)圖象’) 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 仿真結(jié)果
4 參考文獻(xiàn)
[1]孫太生等. "基于改進(jìn)區(qū)域生長算法的焊縫圖像分割." 現(xiàn)代焊接 2(2012):2.
部分理論引用網(wǎng)絡(luò)文獻(xiàn),若有侵權(quán)聯(lián)系博主刪除。
微信掃一掃贊賞作者
贊賞
發(fā)送給作者
人贊賞
長按二維碼向我轉(zhuǎn)賬
受蘋果公司新規(guī)定影響,微信 iOS 版的贊賞功能被關(guān)閉,可通過二維碼轉(zhuǎn)賬支持公眾號。
-
Origin(Pro):學(xué)習(xí)版的窗口限制【數(shù)據(jù)繪圖】 2020-08-07
-
如何卸載Aspen Plus并再重新安裝,這篇文章告訴你! 2020-05-29
-
CAD視口的邊框線看不到也選不中是怎么回事,怎么解決? 2020-06-04
-
教程 | Origin從DSC計算焓和比熱容 2020-08-31
-
Aspen Plus安裝過程中RMS License證書安裝失敗的解決方法,親測有效! 2021-10-15
-
CAD外部參照無法綁定怎么辦? 2020-06-03
-
CAD中如何將布局連帶視口中的內(nèi)容復(fù)制到另一張圖中? 2020-07-03
