Using Hough transform in Matlab,detected some lines. Using the end points of these lines I have plotted them. I cant understand how I can find intersecting lines when I have all the variables.
Line7
Point1 [50,66]
Point2 [11,106]
theta,rho [45,81]
Line9
Point1 [19,83]
Point2 [53,79]
theta,rho [82,84]
Since the parametric equations are as follows
rho = xCos(theta) + ySin(theta)
I am unsure how to solve this. With all this information there must be a quick way of finding if the lines intersect, if so, the points as well.
Any guidance much appreciated.
function FindHoughLines(I,filename)
[H,T,R] = hough(I);
rotI = imrotate(I,0,'crop');
imshow(H,[],'XData',T,'YData',R,...
'InitialMagnification','fit');
xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;
P = houghpeaks(H,10,'threshold',ceil(0.1*max(H(:))));
x = T(P(:,2)); y = R(P(:,1));
plot(x,y,'s','color','white');
% Find lines and plot them
lines = houghlines(I,T,R,P,'FillGap',5,'MinLength',7);
figure, imshow(rotI), hold on
max_len = 0;
for k = 1:length(lines)
if(isField(lines,'point1') ~= 0)
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');
text(xy(1,1),xy(1,2),[ num2str(k)],'HorizontalAlignment','center','BackgroundColor',[.7 .9 .7]);
% 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
end