Question

I have working on a project to extract out the long lines from the image given below. I have no idea how to remove rest of the short lines and small dots from the image. Please give me some hints. My interest lines are both side long lines and middle ones.

enter image description here

After applying RANSAC and some thresh holding operation i get output like below

enter image description here

Was it helpful?

Solution 2

Providing you have the image processing toolbox, you can follow the suggestions of @rayryeng and @Shai and do something like this:

Morphological filtering:

BW1=bwareaopen(YourOriginalBWImage, 100);

Filtered image:

enter image description here

Hough transform (adapted from 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

Result:

enter image description here

OTHER TIPS

For detecting straight lines, better use the well known method of Hough transform.

img = imread('https://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

You'll end up with something like

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top