How to traverse along skeleton just once instead of multiple times?
3 次查看(过去 30 天)
显示 更早的评论
Here is my code
I=im2bw(I);
skel = bwmorph(I,'thin',inf)
boundaries = bwboundaries(skel);
thisBoundary=boundaries{1};
BL=size(thisBoundary(:,2));
figure(1)
imshow(skel)
figure(2)
imshow(I)
hold on
for j=1:1:BL(1)
plot(thisBoundary(j,2), thisBoundary(j,1), '.c', 'LineWidth', 2);
disp(["x: ",num2str(thisBoundary(j,2)), "y: ",num2str(thisBoundary(j,1))])
pause
end
and sample image
As it traverses along the skeleton, at the beginning, you will notice if you pay attention to the outputted x and y values, that as the green points go upwards on the image, eventually it traverses back down and hits the same x,y points again
For example, if you see the output
x: 208 y:22
x: 208 y:21
x: 208 y:20
x: 208 y:21 <-already hit this (x,y) pair 2 lines above
x: 208 y:22 <-already hit this (x,y) pair 4 lines above
Is there a way to somehow sort the values in `thisBoundary` so that it only goes from one endpoint to the other endpoint once as opposed to hitting the same points multiple times?
0 个评论
回答(1 个)
Image Analyst
2018-5-25
I just posted code for this a few days ago. Basically you can skeletonize, prune with the 'spur' option of bwmorph(), and then find branchpoints. and iterate until you have only two endpoints left. Search the forum for endpoint. If you can't find it or do it, let me know.
4 个评论
Image Analyst
2018-5-25
Then just call bwmorph(bw, 'skel', inf) and then call bwmorph() again with the spur option with a big enough factor to chop off any spurs that may be there.
Image Analyst
2018-5-28
We've been working on an algorithm for extracting the longest spine in a crazy-looking skeleton with many arms, but the Mathworks is not quite ready to release it publicly yet. Sorry.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!