Detection of line segments and length
I am trying to have MATLAB detect multiple line segments in a images and then tell the length (in pixels). I have tried the following code:
I=imread('GFP1C2.tif'); canny=edge(I,'canny'); [H,T,R]=hough(canny); imshow(H,[],'XData',T,'YData',R,'InitialMagnification','fit') xlabel('\theta'),ylabel('\rho') axis on, axis normal, hold on P=houghpeaks (H,5,'threshold',ceil(0.8*max(H(:)))); x=T(P(:,2));y=R(P(:,1)); plot(x,y,'s','color','white'); lines=houghlines(BW,T,R,P,'FillGap',5,'MinLength',7); figure,imshow(canny),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(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow'); plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red'); len=norm(lines(k).point1-lines(k).point2); if (len>max_len) max_len=len; xy_long=xy; end end
This code will neither accurately detect the line segments nor will tell me the length of the segment. Help is appreciated; thanks!
10 Comments
Hi, Victoria,
I was playing around with curvature filters and your image. What I found suggests that the filaments in your image do not have a coherent direction and thus cannot be easily segmented. Rather, the structure in your image is more like a matrix composed of interweaving fibers:
In view of this, how would you define the beginning and end of a single "line segment"?
Accepted Answer
0 Comments
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!