0

I am trying to detect the white straight lines on the image using the hough transform.

Binary image with White = 1, Black= 0 - Lines detected in green and longest line detected in red

The following code only detects sections of a curved line as straight and is ignoring (failing to identify) the truly straight lines. How can I modify it to find only the proper straight lines among the white lines?

    load('image.mat')

    %Binarize image

    image(image== 0) = 1;
    image= image- ones(size(image),'int8');
    image= logical(image);
    % imshow(BW_active,[0 1])


    [H,theta,rho] = hough(image, 'RhoResolution',0.5);
    P = houghpeaks(H);
    lines = houghlines(image,theta,rho,P);      %,'FillGap',20,'MinLength',7);

    figure, imshow(image, [0 1]), hold on
    max_len = 0;

    % from Mathworks
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)image
      max_len = len;
      xy_long = xy;
   end
end
    % highlight the longest line segment
    plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','red');

Here there is the .mat file. https://drive.google.com/file/d/0BxCvoDCdJJYoOFZLeklCX2dzc2c/view?usp=sharing

roadRunner
  • 100
  • 1
  • 9
  • 1
    "`hough(BW)` computes the Standard Hough Transform (SHT) of the **binary image BW**" Is your image binary? – beaker Jan 13 '17 at 16:15
  • @beaker , Thank you for pointing that out. I modified my script and the question accordingly, but still no results. – roadRunner Jan 16 '17 at 02:39

0 Answers0