python - Finding midlines of polygons using Voronoi diagrams
问题描述
I am using the Voronoi diagram-based approach outlined here to find midlines of binary masks of root images. I am using the Python code more or less exactly as described:
import skimage.morphology as morphology
WHITE = 255
image_bool = binary_mask == WHITE
d = morphology.disk(2)
img = morphology.binary_closing(image_bool, selem=d)
skeleton = morphology.medial_axis(img)
Then comes the graphing: I feed the skeletonized image into buildTree, as described in user Gabriel's iPython notebook: https://github.com/gabyx/WormAnalysis/blob/master/SkeletonTest/Skeletonize.ipynb
In general, this produces great results. However, the method occasionally fails in two distinct ways:
1) The graphs do not always extend the full length of the root:
2) The graphs sometimes connect "prematurely" to a point along the root contour that may appear to be the longest path, but clearly does not conform to what I would call the "midline". This happens for a diverse range of polygon shapes:
This final case is an artificial mask -- none of my actual roots have perfectly flat tips -- but I think it represents the problem quite well.
Does anyone with a more refined understanding of Voronoi diagrams have any tips for how to address either of these problems, while still retaining this general approach.
Thanks!
解决方案
这两个问题都是中轴的“特征”,Voronoi 方法。
中轴上的点具有与两个或多个边界等距的特性。这是由于中轴点是 Voronoi 点,或双重 Delaunay 三角测量中心。这意味着有一个以该中心为中心的圆,整个在边界内,通过三个边界点。至少当边界离散化进入无穷大时会出现这种情况。由于边界没有无限数量的点,这种方法是您观察到的问题的近似值。
1)圆弧的中轴是一个点。这个结果很好。如果形状以非常干净的弧线结束,则中间轴“停止”在弧形部分的中间轴点上。这可以从Skeletonize 页面上不同方法的比较中看出。
2)两条线的中轴通过角平分线。这意味着如果边界上有更多的“角”,就会有更多的轴“指”进入这些角。就像正方形的中轴是X形的。如果您使用 WormAnalysis 方法(您提到过),则仅提取轴上最长的路径。这对蠕虫有好处,但不是在一般情况下。在一般情况下,最好通过移除覆盖一小部分边界的部分来清洁轴。就像您在主题 2 的第一张图片中一样,有一个轴部分在上升。即部分是边界左上角小角的中轴。边界上那个角的左侧是具有小中轴的弧形部分。因为走最长的路,所以走的那个长“手指”覆盖了边界的一小部分,
推荐阅读
- php - Puphpeteer - 从链接获取文本和 href 属性
- python - 如何手动进行傅里叶变换
- gradle - 在 grails 4.0.11 中生成文档会返回 ClassNotFoundException:groovy.text.Template
- python - 用 isin 子集数据表
- node.js - nodejs express + create-react-app oauth2.0 error 401 'Invalid access token' Spotify API
- java - Liferay 7.1.3 GA4 自定义 Portlet 与番石榴依赖部署:灾难性初始化失败!TypeNotPresentExceptionProxy
- java - 使用 Apache Beam FileIO 时如何避免截断数据
- mongodb - 通过 id 数组删除整个对象
- javascript - 如何从输入掩码中删除此警告
- kubernetes - 以编程方式颁发 Kubernetes 证书