修剪python图像骨架并找到最长路径

问题描述

我有以下图片,我想从中修剪树枝:

输入:

enter image description here

当我使用Python Image - Finding largest branch from image skeleton中描述的方法时 我得到这个结果:

最长路径:

enter image description here

但是我想要的结果是这样的:(人工制作)

所需的输出

enter image description here

使用的代码

from fil_finder import FilFinder2D
import astropy.units as u

fil = FilFinder2D(skeleton2,distance=250 * u.pc,mask=skeleton2)
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')

# Show the longest path
plt.imshow(fil.skeleton,cmap='gray')
plt.contour(fil.skeleton_longpath,colors='r')
plt.axis('off')
plt.show()

我想也许可以通过找到分支点然后删除最短路径来获得所需的输出。有谁知道如何实现这一目标?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)