8
$\begingroup$

I want to get the branching coordinates from a computer-generated image like this one:

Generated tree

After SkeletonTransform and Pruning, I get:

Skeletonized

I would like to develop an algorithm that automatically detect and give coordinates of branching points (I could do it manually but really time consuming).

Thanks!

Edit: I already tried MorphologicalBranchPoints with poor results...

$\endgroup$
  • 1
    $\begingroup$ "I already tried MorphologicalBranchPoints with poor results..." Can you be specific about what you got and what you want instead? $\endgroup$ – Szabolcs Feb 18 '19 at 14:48
  • $\begingroup$ @ Szabolcs It was more about a careful selection of thinning and skeletonize options. The result with MorphologicalBranchPoints wasn't good then. $\endgroup$ – Valacar Feb 18 '19 at 15:08
  • 1
    $\begingroup$ Added another update. $\endgroup$ – Szabolcs Feb 18 '19 at 15:09
13
$\begingroup$

Use MorphologicalBranchPoints.

im = Binarize@Import["https://i.stack.imgur.com/O0AMj.png"]

skel = Pruning[Thinning[im], 20];

HighlightImage[skel, MorphologicalBranchPoints[skel]]

enter image description here

Another possibility is to use

skel1 = Pruning[Thinning[im, Method -> "MedialAxis"], 10];

as a start then smoothen the result using

skel2 = Thinning@Dilation[skel1, 5]

so that MorphologicalBranchPoints would not give false results.

HighlightImage[skel2, MorphologicalBranchPoints[skel2]]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Great ! Thanks a lot. $\endgroup$ – Valacar Feb 18 '19 at 15:09
7
$\begingroup$

I notice there's a faint pink background that seems like a natural boundary. I've highlighted it to showcase this:

enter image description here

We can extract this curve and use it as the original boundary:

im = Import["https://i.stack.imgur.com/7Ck2S.png"];
mask = FillingTransform[Thinning[Binarize[ColorReplace[im, White -> Black, .055], 0]], CornerNeighbors -> True]

enter image description here

And the simply call MorphologicalBranchPoints:

skel = Thinning[mask];
HighlightImage[skel, MorphologicalBranchPoints[skel], 1]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ This is really clean! $\endgroup$ – Valacar Feb 19 '19 at 9:24
  • $\begingroup$ by the way I think it's Thinning[mask] in this case, isn't it? $\endgroup$ – Valacar Feb 19 '19 at 12:26
  • $\begingroup$ @Valacar Yes. I made the correction, thank you. $\endgroup$ – Chip Hurst Feb 19 '19 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.