Remove outside lines from the image
Show older comments
I use hough function for line detection. but lines on the outside of the image are also detected.

%Edge detection
BW1 = edge(wiener,'sobel');
%Hough Function
BW1 = imrotate(BW1,0,'crop');
figure, imshow(BW1);
[H,theta,rho] = hough(BW1);
figure, imshow(imadjust(mat2gray(H)),[],'XData',theta,'YData',rho,...
'InitialMagnification','fit');
xlabel('\theta (degrees)'), ylabel('\rho');
axis on, axis normal, hold on;
colormap(hot)
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
x = theta(P(:,2));
y = rho(P(:,1));
plot(x,y,'s','color','black');
lines = houghlines(BW1,theta,rho,P,'FillGap',5,'MinLength',10);
figure, imshow(BW1), hold on
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
%assign values to arrays
arr1Yx(:,k) = xy(1,1);
arr2Yy(:,k) = xy(1,2);
arr3Rx(:,k) = xy(2,1);
arr4Ry(:,k) = xy(2,2);
%Separate line1 and line2 array
if xy(1,1) > value
line1(:,k) = xy(1,1);
line1Y(:,k) = xy(1,2);
value = xy(1,1);
elseif xy(1,1) < value
fprintf('Line 2 - %d - %d\n', startline2, value);
line2(:,k) = xy(1,1);
line2Y(:,k) = xy(1,2);
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Object Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!