how I extract all straight line co-ordinates from hough transform ?
1 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/164360/image.png)
After hough transform I get some horizontal lines. I want to read this horizontal line data , for example: co-ordinates of those lines. Here is the code :
BW=imread('a.png');
[H,theta,rho] = hough(BW);
% figure
% imshow(imadjust(mat2gray(H)),[],...
% 'XData',theta,...
% 'YData',rho,...
% 'InitialMagnification','fit');
% xlabel('\theta (degrees)')
% ylabel('\rho')
% axis on
% axis normal
% hold on
% colormap(gca,hot);
P = houghpeaks(H,10,'threshold',ceil(0.5*max(H(:))));
% x = theta(P(:,2));
% y = rho(P(:,1));
% plot(x,y,'s','color','black');
lines = houghlines(BW,theta,rho,P,'FillGap',50,'MinLength',20);
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');
5 个评论
回答(1 个)
KSSV
2017-5-24
Already you have the lines coordinates in hand. Check lines. You are plotting them too.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!