I'm trying to measure the longest and the transverse branchs of a banana picture, using skimage to get the skeleton and then using fil_finder to get the length of the longest branch , the code is adapted from this post
Ideas how to measure the length of a skeleton using python
but i can't get it fil_finder to work with the skeleton output of skimage, i get the following error:
raise TypeError("Data must be 2D. Please re-check the inputs.")
TypeError: Data must be 2D. Please re-check the inputs.
skeleton made using skimage banana picture used in code
any help solving the error and updates to code if any needed to measure the length of longest and transverse length
from skimage import io,img_as_float
from skimage.morphology import skeletonize
from matplotlib import pyplot as plt
from skimage.util import invert
import numpy as np
from fil_finder import FilFinder2D
import astropy.units as u
image=img_as_float(io.imread('C:/python/fruits/banana.jpg'))
gray = invert(image)
skeleton=skeletonize(gray)
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()