After applying skeletonization on an image(),
I want to measure the longest branch, or spine of the skeleton using python. ImageJ has several tools that do this job one is Measure_Skeleton_length, another is AnalyzeSkeleton. Any tools or suggestions in python?
This comes as a very late reply to the original question, but just in case someone who still is in need might end up reading this post. There is an awesome python package for analyzing skeletons called FilFinder
(pip install fil_finder
) which solves this problem elegantly. Below is a code adopted from their tutorial
import numpy as np
import cv2
import matplotlib.pyplot as plt
from fil_finder import FilFinder2D
import astropy.units as u
skeleton = ... #in numpy array format
fil = FilFinder2D(skeleton, distance=250 * u.pc, mask=skeleton)
fil.preprocess_image(flatten_percent=85)
fil.create_mask(border_masking=True, verbose=False,
use_existing_mask=True)
fil.medskel(verbose=False)
fil.analyze_skeletons(branch_thresh=40* u.pix, skel_thresh=10 * u.pix, prune_criteria='length')
plt.imshow(fil.skeleton, cmap='gray')
plt.contour(fil.skeleton_longpath, colors='r')
plt.axis('off')
plt.show()
which outputs