我有很多这样的骨架图像:
我如何检测骨架中的循环?
是否有“特殊”函数可以执行此操作,或者我应该将其实现为图表?
如果只有图形选项,python图形库NetworkX可以帮助我吗?
您可以利用骨架的拓扑结构。循环不会有洞,所以我们可以使用scipy.ndimage
找到任何漏洞并进行比较。这不是最快的方法,但它非常容易编码。
import scipy.misc, scipy.ndimage
# Read the image
img = scipy.misc.imread("Skel.png")
# Retain only the skeleton
img[img!=255] = 0
img = img.astype(bool)
# Fill the holes
img2 = scipy.ndimage.binary_fill_holes(img)
# Compare the two, an image without cycles will have no holes
print "Cycles in image: ", ~(img == img2).all()
# As a test break the cycles
img3 = img.copy()
img3[0:200, 0:200] = 0
img4 = scipy.ndimage.binary_fill_holes(img3)
# Compare the two, an image without cycles will have no holes
print "Cycles in image: ", ~(img3 == img4).all()
我用你的“B”图片作为例子。前两张图像是原始图像和检测循环的填充版本。在第二个版本中,我打破了循环,没有任何内容被填充,因此两个图像是相同的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)