Hi,
my goal is to count and measure (length, position in the image) the black thin lines in the attached image. I tried already several appoaches, the most promising was with the hough transformation (see attached code), but still not good enough.
Had anybody a simililar problem or an idea how to solve the task?
Thanks a lot!
clear variablesclose all%Read Iimage
I = imread('Find_gaps.PNG');%binarize image
BW = im2bw(I);%get edges
BW = edge(BW,'canny');figure, imshow(BW)%Hough transformation and find peaks
[H,theta,rho] = hough(BW);figureimshow(imadjust(rescale(H)),[],... 'XData',theta,... 'YData',rho,... 'InitialMagnification','fit');xlabel('\theta (degrees)')ylabel('\rho')axis onaxis normal hold oncolormap(gca,hot)P = houghpeaks(H,20,'threshold',ceil(0.3*max(H(:))));x = theta(P(:,2));y = rho(P(:,1));plot(x,y,'s','color','black');lines = houghlines(BW,theta,rho,P,'FillGap',5,'MinLength',10);%Plot
figure, imshow(I), hold onmax_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; endend% highlight the longest line segment
plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','red');
Best Answer