How to traverse along skeleton just once instead of multiple times?

6 vues (au cours des 30 derniers jours)
asdf
asdf le 25 Mai 2018
Modifié(e) : asdf le 30 Mai 2018
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?

Réponses (1)

Image Analyst
Image Analyst le 25 Mai 2018
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 commentaires
Image Analyst
Image Analyst le 25 Mai 2018
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
Image Analyst le 28 Mai 2018
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.

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by