To recognize line objects in your figure window, you may use the HOUGH Transform. Information about the HOUGH transform may be found at the following location:
<http://www.mathworks.com/help/toolbox/images/ref/hough.html>
As a simple example, run the following code on the attached file "test.jpg":
I = imread('test.jpg');
Igray = rgb2gray(I);
figure, imshow(I);
Ibw = im2bw(Igray,graythresh(Igray));
se = strel('line',3,90);
cleanI = imdilate(~Ibw,se);
figure, imshow(cleanI);
[H,theta,rho] = hough(cleanI);
peaks = houghpeaks(H,10);
lines = houghlines(Ibw,theta,rho,peaks);
figure, imshow(cleanI)
hold on
for k = 1:numel(lines)
x1 = lines(k).point1(1);
y1 = lines(k).point1(2);
x2 = lines(k).point2(1);
y2 = lines(k).point2(2);
plot([x1 x2],[y1 y2],'Color','g','LineWidth', 2)
end
hold off
lines(1).theta
lines(2).theta
Best Answer