Tal_Rofe

t5_5

Jan 21st, 2018
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.77 KB | None | 0 0
  1. function [] = lineHoughFunc(image, threshold, sigma, npeaks)
  2.     e = edge(image, 'Canny', threshold, sigma);
  3.     [H, th, d] = hough(e);
  4.     peaks = houghpeaks(H, npeaks);
  5.     lines = houghlines(e, th, d, peaks);
  6.    
  7.     figure, imshow(image), hold on
  8.     max_len = 0;
  9.     for k = 1:length(lines)
  10.        xy = [lines(k).point1; lines(k).point2];
  11.        plot(xy(:,1),xy(:,2),'LineWidth',3,'Color','green');
  12.  
  13.        % Plot beginnings and ends of lines
  14.        plot(xy(1,1),xy(1,2),'x','LineWidth',3,'Color','yellow');
  15.        plot(xy(2,1),xy(2,2),'x','LineWidth',3,'Color','red');
  16.  
  17.        % Determine the endpoints of the longest line segment
  18.        len = norm(lines(k).point1 - lines(k).point2);
  19.        if ( len > max_len)
  20.           max_len = len;
  21.        end
  22.     end
  23. end
Add Comment
Please, Sign In to add comment