How can I detect every line with Hough method?

2 views (last 30 days)
I am trying to detect all possible lines in an image with hough method, however I need to adjust the "MinLength" and "FİllGap" for better results, my question as I mentioned in the headline, is there any way to detect all possible lines with a special function or something else? The code I used is given and the image is added.
I = imread("line2.png");
BW2gray = rgb2gray(I);
BW = edge(BW2gray,"canny");
[H,theta,rho] = hough(BW);
P = houghpeaks(H,10,'threshold',ceil(0.3*max(H(:))));
x = theta(P(:,2));
y = rho(P(:,1));
lines = houghlines(BW,theta,rho,P,'FillGap',20,'MinLength',50);
figure, imshow(BW), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
for i = 1:length(lines)
velocityX(i) = lines(i).point2(1,1)-lines(i).point1(1,1);
velocityY(i) = -lines(i).point2(1,2)-lines(i).point1(1,2);
fprintf("the velocity vector of line %d is %fi %dj \n",i,velocityX(i),velocityY(i));

Answers (1)

Aritra on 23 Nov 2022
Hi Furkan,
As per my understanding you are trying to detect all possible lines in an image using the Hough method. This can be achieved by using the houghlines(BW,theta,rho,peaks)function which is designed to extract line segments in images based on Hough transform.
For detail, please see this MathWorks documentation below for more information on Image Transforms:




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!