从短线图像中提取长线作为噪声?

时间:2014-05-15 10:37:41

标签: matlab image-processing computer-vision

我正在开展一个项目,从下面给出的图像中提取出长行。我不知道如何从图像中删除其余的短线和小点。请给我一些提示。我的兴趣线是长边线和中线线。

enter image description here

应用RANSAC和一些thresh保持操作后,我得到如下输出

enter image description here

2 个答案:

答案 0 :(得分:3)

为了检测直线,最好使用Hough transform的众所周知的方法。

img = imread('http://i.stack.imgur.com/V6bDn.png');
bw = rgb2gray( imcrop( bw, [85 35 390 290] ) ) > 128; % crop and threshold image
[H,T,R] = hough(bw,'RhoResolution',0.5,'ThetaResolution',0.5);
P  = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))),'NHoodSize',[31, 11]);
lines = houghlines(bw,T,R,P,'FillGap',25,'MinLength',30);
% display the result
figure;imshow(bw);hold on;
for k = 1:length(lines), 
    xy = [lines(k).point1; lines(k).point2];
    plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
end

你最终会得到像

这样的东西

enter image description here

答案 1 :(得分:2)

如果你有图像处理工具箱,你可以按照@rayryeng和@Shai的建议做这样的事情:

形态过滤:

BW1=bwareaopen(YourOriginalBWImage, 100);

已过滤的图片:

enter image description here

Hough变换(改编自this):

[H,theta,rho] = hough(BW1);
P = houghpeaks(H,7,'threshold',ceil(0.3*max(H(:))));
lines = houghlines(BW1,theta,rho,P,'FillGap',5,'MinLength',3);
figure, imshow(YourOriginalBWImage), hold on
for k = 1:length(lines)
   xy = [lines(k).point1; lines(k).point2];
   plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
end

结果:

enter image description here