微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决修剪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 举报,一经查实,本站将立刻删除。