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

8 次查看(过去 30 天)
%% 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