why hough transform detects more lines while there is only one line?

조회 수: 8 (최근 30일)
muhamad
muhamad 2021년 6월 1일
편집: Matt J 2021년 6월 2일
%% Hough Transform
I4 = imbinarize(I4);
BW2 = imcomplement(I4);
[H,theta,rho] = hough(BW2,'RhoResolution',1.8);
figure(2);
imshow(imadjust(rescale(H)),'XData',theta,...
'YData',rho,...
'InitialMagnification','fit');
axis on
axis normal
hold on
colormap(gca,hot)
P = houghpeaks(H,40,'threshold',ceil(0.05*max(H(:))));
x = theta(P(:,2));
y = rho(P(:,1));
lines = houghlines(BW2,theta,rho,P,'FillGap',3,'MinLength',36);
figure(1);subplot(2,2,4);
imshow(I4),
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','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');
end

채택된 답변

Matt J
Matt J 2021년 6월 2일
편집: Matt J 2021년 6월 2일
Because your line is actually not a line, but rather a tube with non-zero thickness, there are multiple thinner lines that will fit inside it. The number that are found depend on the boundaries of your rho and theta bins.
You can use clusterdata or uniquetol to group the redundant line tip detections into single points.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by