How can I keep just the main line on this skeleton?

I have a number of plants that I want to analyze the stem and they produce skeletons like this one. I want to keep just the main line.

I have tried a number of things like erosion on the source image as to thin the branches and disconnect them from stem, erosion to the point the whole stem were gone and then subtracting the leafs from the original image and also putting black pixels around the branch connections as to disconnect them from stem.

The erosion aproach proved to be inconsistent between images due to difference between plants.

As I’ḿ still learning about classic CV that was all I could think of…

The main problem with the black pixels on the skeleton aproach, is that I don’t know how to reconnect the segments “only of the main line”. I guess I would need something to fill in the line in a way it “goes the right path”

I would think that if would be easier just use mask-rcnn and train it to segment the stem … as I’m already using it somewhere else…

Ideas on how I can solve this problem using classic CV ?

BTW, Iḿ using python for this one.

Thank you

Have you try thining algorithm?


thinning is skeletonization, as far as I understand it, so that’s precisely the issue.

when you skeletonize, all the lines, no matter if it’s the thick stem or thin capillaries, become “same”. this way you’re discarding the vital piece of information.

I agree, using deep learning segmentation sounds like a good approach, if you have the data to train/retrain a network to the task.

as for classic cv, I’d need to see the original picture (as always) for a decent opinion. specific lighting is often the best measure. then perhaps selecting on color/hue/saturation, and morphological operations to remove capillaries and keep the stem.