필터 지우기
필터 지우기

how I extract all straight line co-ordinates from hough transform ?

조회 수: 1 (최근 30일)
sufian ahmed
sufian ahmed 2017년 5월 23일
답변: KSSV 2017년 5월 24일
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
KSSV
KSSV 2017년 5월 24일
YOu must attach image too...

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
KSSV 2017년 5월 24일
Already you have the lines coordinates in hand. Check lines. You are plotting them too.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by