I have posted a related but not the same question here https://stackoverflow.com/questions/8279698/measuring-length-of-dna-fibers-from-an-image-of-single-molecules
Background: I have many images that look like this:
I would like to identify all line segments that are co-linear and then measure the length of these segments. In the image above there are 3 pairs of segments that are on an imaginary line with a negative slope. The line segment that is the longest does not have a pair so it would not be considered i.e. there must be atleast 2 segments that are colinear.
I get the following:
I = imread('http://dl.dropbox.com/u/18072545/c_39_green.tif');
BW = edge(I,'canny');
[H,T,R] = hough(BW);
NUMPEAKS=15;
PEAKTHRESHOLD= 80;
SUPPRESSNHBR=[40 40];
P = houghpeaks(H,NUMPEAKS,'threshold',PEAKTHRESHOLD,'NHoodSize',SUPPRESSNHBR);
MINLENGTH_OF_SEGMENT=50;
GAPLENGTH_TO_MERGE=30;
lines = houghlines(BW,T,R,P,'FillGap',GAPLENGTH_TO_MERGE,'MinLength',MINLENGTH_OF_SEGMENT);
max_len = 0;
figure, imshow(I), hold on
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');
end
I had to play around with the parameters in order to get a reasonable performance (though I am unable to find a parameter that will capture the starting bit of the segment that is at the bottom). However, I am unable to avoid finding multiple segments that are overlapping.
Can someone please help me 1. Prevent identification of overlapping segments. 2. Identify all the lines that are co-linear
Many thanks!