Segmentation of interconnected lines

Hi!
I'm working on a project that require to segment shapes or features from an image. My actual approach is to first detect all lines with Hough Transform and after try to segment each line by its slope, hower I've tried k-means, DBSCAN, and I didn't get the result that I would like to achieve.
I would like to know if someone can help me with a idea or documentation.
Thank You!

5 comentarios

Jan
Jan el 5 de Nov. de 2022
Please include the images directly instead of letting the readers download them from an external service.
James Ben
James Ben el 5 de Nov. de 2022
Thanks for the feedback, I alrealy included the image on the question description.
Image Analyst
Image Analyst el 6 de Nov. de 2022
OK, good but you forgot to include your code. Give us a head start by including your Hough code and clustering code. What sort of clusters would you like? Like horizontal lines and vertical lines? You can do that just with thresholding the slopes vector, but I guess you could use kmeans if you want. I'm not sure dbscan would be appropriate - I can't see that so not sure what the rationale for dbscan was.
James Ben
James Ben el 6 de Nov. de 2022
Editada: James Ben el 6 de Nov. de 2022
I would like to extract each shape separately from the image. I've done a look on the bwlabel() method due the curved lines, but I didn't know how to implement in my code.
Here is my actual code:
RGB = imread('link_PRE.png');
I = im2gray(RGB);
% Extract edges
BW = edge(I,'canny');
% % Calculate Hough Transform
[H,T,R] = hough(BW,"RhoResolution",0.5,"Theta",-90:0.1:89);
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
%Find lines and plot them.
lines = houghlines(BW,T,R,P,'FillGap',50,'MinLength',0.5);
figure, imshow(I), 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 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;
end
end
James Ben
James Ben el 9 de Nov. de 2022
@Image Analyst I'm waiting for your answer, plz!

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 10 de Nov. de 2022
Movida: Image Analyst el 10 de Nov. de 2022
You can get all the angles like this:
lines = houghlines(BW,T,R,P,'FillGap',50,'MinLength',0.5)
allAngles = [lines.theta]
If you want to get each segment individually find crossing points and delete them, then label the image. Untested code:
% Find branchpoints
bpImage = bwmorph(BW, 'branchpoints');
% Erase branchpoints from main binary image.
BW(bpImage) = false;
% Label what's left.
[labeledImage, numSegments] = bwlabel(BW, 4);
% Show them all one at a time.
for k = 1 : numSegments
thisImage = ismember(labeledImage, k);
imshow(thisImage);
drawnow;
% Delay a bit so we can see it.
pause(0.5);
end

Más respuestas (0)

Preguntada:

el 5 de Nov. de 2022

Movida:

el 10 de Nov. de 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by