0

I am trying use hough transform to find the edge, the following image's right-below corner line can't be found. why?

My code

BW = imread("edge/30.1.tif");
[H,theta,rho] = hough(BW);
imshow(imadjust(rescale(H)),[],...
       'XData',theta,...
       'YData',rho,...
       'InitialMagnification','fit');
xlabel('\theta (degrees)')
ylabel('\rho')
axis on
axis normal 
hold on
colormap(gca,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(BW,theta,rho,P,'FillGap',5,'MinLength',7);

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','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');

   % Determine the endpoints of the longest line segment
   len = norm(lines(k).point1 - lines(k).point2);
   if ( len > max_len)
      max_len = len;
      xy_long = xy;
   end
end
% highlight the longest line segment
plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','red');

raw image

hough transform image

Chen Yu
  • 3,955
  • 1
  • 24
  • 51
  • 1
    related. possibly even very related... https://stackoverflow.com/questions/71368930/houghlines-not-reaching-edge-of-image/71406060#71406060 – bla May 05 '22 at 07:58
  • the houghpeak default value is 5, it is too small. – Chen Yu May 06 '22 at 03:11

0 Answers0