Matlab图像中的自主接缝检测 [英] Autonomous seam detection in Images on matlab
问题描述
我正在尝试检测焊接图像中的接缝,以实现自主焊接过程. 我想在原始图像中找到检测到的线(所需图像中的红线)的像素位置.
I'm trying to detect seams in welding images for an autonomous welding process. I want to find pixel positions of the detected line (the red line in the desired image) in the original image.
我使用了以下代码,最终去除了图像中的噪点,从而达到了以下结果.
I used the following code and finally removed noise from the image to reach the result below.
clc,clear,clf;
im = imread('https://i.stack.imgur.com/UJcKA.png');
imshow(im);title('Original image'); pause(0.5);
sim = edge(im, 'sobel');
imshow(sim);title('after Sobel'); pause(0.5);
mask = im > 5;
se = strel('square', 5);
mask_s = imerode(mask, se);
mask(mask_s) = false;
mask = imdilate(mask, se);
sim(mask) = false;
imshow(sim);title('after mask');pause(0.5);
sim= medfilt2(sim);
imshow(sim);title('after noise removal')
不幸的是,图像中没有剩余东西可以完美地找到接缝.
Unfortunately there is nothing remaining in the image to find the seam perfectly.
任何帮助将不胜感激.
下载原始图像.
推荐答案
您需要使滤波器对噪声更加鲁棒.可以通过提供更大的支持来实现:
You need to make your filter more robust to noise. This can be done by giving it a larger support:
filter = [ones(2,9);zeros(1,9);-ones(2,9)];
msk = imerode(im > 0, ones(11)); % only object pixels, discarding BG
fim =imfilter(im,filter);
robust = bwmorph((fim>0.75).*msk,'skel',inf); % get only strong pixels
健壮的面具看起来像:
如您所见,接缝线已被很好地检测到,我们只需要选择它作为最大的连接组件:
As you can see, the seam line is well detected, we just need to pick it as the largest connected component:
st = regionprops(bwlabel(robust,8), 'Area', 'PixelList');
[ma mxi] = max([st.Area]); % select the region with the largest area
现在,我们可以将多边形(第2度)拟合为外观了:
Now we can fit a polygon (2nd degree) to the seem:
pp=polyfit(st(mxi).PixelList(:,1), st(mxi).PixelList(:,2), 2);
这是图片的上方:
imshow(im, 'border','tight');hold on;
xx=1:size(im,2);plot(xx,polyval(pp,xx)+2,'r');
请注意由于滤镜宽度而导致的+2
Y偏移量.
Note the +2
Y offset due to filter width.
PS,
您可能会发现此线程相关.
PS,
You might find this thread relevant.
这篇关于Matlab图像中的自主接缝检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!