Segmentation of interconnected lines

조회 수: 6 (최근 30일)
James Ben
James Ben 2022년 11월 5일
이동: Image Analyst 2022년 11월 10일
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
James Ben
James Ben 2022년 11월 6일
편집: James Ben 2022년 11월 6일
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 2022년 11월 9일
@Image Analyst I'm waiting for your answer, plz!

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2022년 11월 10일
이동: Image Analyst 2022년 11월 10일
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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by