如何从二进制骨架化图像中找到分支点 [英] How to find branch point from binary skeletonize image

查看:48
本文介绍了如何从二进制骨架化图像中找到分支点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Python OpenCV来骨架化这样的图像:

I use Python OpenCV to skeletonize an image like this:

我想找到骨骼的分支点

我不知道该怎么做.有什么想法吗?

I have no idea how to do it. Any thoughts?

推荐答案

这个问题已经很老了,但是如果其他任何人偶然发现了这个问题,并且希望得到一个不依赖于其他软件包并且使用简单形态学运算的答案,可能会发现以下帮助.

This question is already quite old but if anyone else stumbles across this and would like to have an answer that does not rely on additional packages and uses simple morphological operations you might find the following helpful.

这个想法只是简单地应用命中或未命中"变换来搜索满足分支点条件的像素.骨架中的分支点是连接到其他三个或四个像素的像素.给定适当的结构元素 selems 的列表,您可以在一个输出图像中优雅地组合几个命中或未命中的转换,如下所示.

The idea is simply to apply a hit-or-miss transform to search for pixels that satisfy the condition of a branchpoint. A branchpoint in a skeleton is a pixel that is connected to three or four other pixels. Given a list of appropriate structuring elements selems you can elegantly combine several hit-or-miss transforms in one output image like the following.

import numpy as np
import scipy.ndimage as ndi


branches = np.zeros_like(skeleton, dtype=bool)
for selem in selems:
    branches |= ndi.binary_hit_or_miss(skeleton, selem)

这非常节省空间,因为您可以将每个转换的结果直接添加到同一结果数组中.现在的问题是如何创建结构元素列表.一种解决方法如下.

This is quite space efficient because you directly add the result of each transform to the same result array. The question now is how to create the list of structuring elements. One solution would be the following.

selems = list()
selems.append(np.array([[0, 1, 0], [1, 1, 1], [0, 0, 0]]))
selems.append(np.array([[1, 0, 1], [0, 1, 0], [1, 0, 0]]))
selems.append(np.array([[1, 0, 1], [0, 1, 0], [0, 1, 0]]))
selems.append(np.array([[0, 1, 0], [1, 1, 0], [0, 0, 1]]))
selems = [np.rot90(selems[i], k=j) for i in range(4) for j in range(4)]

selems.append(np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]]))
selems.append(np.array([[1, 0, 1], [0, 1, 0], [1, 0, 1]]))

仅当您还要检测带有四个分支的分支点时,才需要最后两行.如果您只对三个分支感兴趣,则可以省略最后两行.

The last two lines are only needed if you want to also detect branch points with four branches. If you're only interested in three branches you can omit the last two lines.

那么完整的解决方案就是

The complete solution would then be

import numpy as np
import scipy.ndimage as ndi


selems = list()
selems.append(np.array([[0, 1, 0], [1, 1, 1], [0, 0, 0]]))
selems.append(np.array([[1, 0, 1], [0, 1, 0], [1, 0, 0]]))
selems.append(np.array([[1, 0, 1], [0, 1, 0], [0, 1, 0]]))
selems.append(np.array([[0, 1, 0], [1, 1, 0], [0, 0, 1]]))
selems = [np.rot90(selems[i], k=j) for i in range(4) for j in range(4)]

selems.append(np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]]))
selems.append(np.array([[1, 0, 1], [0, 1, 0], [1, 0, 1]]))

branches = np.zeros_like(skeleton, dtype=bool)
for selem in selems:
    branches |= ndi.binary_hit_or_miss(skeleton, selem)

同样,您可以使用以下结构元素列表来搜索端点.

Likewise you can search for endpoints by using the following list of structuring elements.

selems = list()
selems.append(np.array([[0, 1, 0], [0, 1, 0], [0, 0, 0]]))
selems.append(np.array([[1, 0, 0], [0, 1, 0], [0, 0, 0]]))
selems = [np.rot90(selems[i], k=j) for i in range(2) for j in range(4)]

这篇关于如何从二进制骨架化图像中找到分支点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆