| | 126 | |
| | 127 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%5 |
| | 128 | |
| | 129 | [H,T,R] = hough(line_mask); |
| | 130 | imshow(H,[],'XData',T,'YData',R,'InitialMagnification','fit'); |
| | 131 | xlabel('\theta'), ylabel('\rho'); |
| | 132 | axis on, axis normal, hold on; |
| | 133 | P = houghpeaks(H,5,'NHoodSize',[161,161])%ceil(0.3*max(H(:)))); |
| | 134 | x = T(P(:,2)); |
| | 135 | y = R(P(:,1)); |
| | 136 | plot(x,y,'s','color','white'); |
| | 137 | |
| | 138 | lines = houghlines(line_mask,T,R,P,'FillGap',5,'MinLength',7); |
| | 139 | figure, imshow(im_rgb), hold on |
| | 140 | max_len = 0; |
| | 141 | for k = 1:length(lines) |
| | 142 | xy = [lines(k).point1; lines(k).point2]; |
| | 143 | plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green'); |
| | 144 | |
| | 145 | % plot beginnings and ends of lines |
| | 146 | plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow'); |
| | 147 | plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red'); |
| | 148 | |
| | 149 | % determine the endpoints of the longest line segment |
| | 150 | len = norm(lines(k).point1 - lines(k).point2); |
| | 151 | if ( len > max_len) |
| | 152 | max_len = len; |
| | 153 | xy_long = xy; |
| | 154 | end |
| | 155 | end |
| | 156 | |
| | 157 | % highlight the longest line segment |
| | 158 | plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','cyan'); |
| | 159 | |
| | 160 | |
| | 161 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |