How can I detect every line with Hough method?

5 visualizzazioni (ultimi 30 giorni)
Furkan Bayazit
Furkan Bayazit il 20 Ott 2022
Risposto: Aritra il 23 Nov 2022
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];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','cyan');
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','red');
plot(xy(2,1),xy(2,2),'>','LineWidth',2,'Color','cyan');
end
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));
end

Risposte (1)

Aritra
Aritra il 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: https://in.mathworks.com/help/images/image-transforms.html?s_tid=CRUX_lftnav

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by