我试图在二值图像中填充漏洞。图像相当大,所以我把它分成几块进行处理。在
当我使用scipy.ndimage.morphology.binary_fill_holes
函数时,它会填充图像中更大的洞。因此,我尝试使用scipy.ndimage.morphology.binary_closing
,它给出了填充图像中小孔的理想结果。但是,当我把这些块放回一起时,为了创建整个图像,我最终得到的是缝合线,因为binary_closing
函数会从每个块的边界像素中删除任何值。在
有没有办法避免这种影响?在
Tags:
是的。在
ndimage.label
标记图像(首先反转图像,holes=black)。在ndimage.find_objects
查找孔对象切片binary_fill_holes
。在这样就可以了,而不需要将图像切碎。例如:
输入图像:
{1美元^
输出图像(中等大小的孔消失):
下面是代码(设置不等式以删除中等大小的blob):
还需要注意的是,我必须增加切片的大小,这样孔就可以在所有的方向上都有边界。在
涉及来自相邻像素的信息的操作,例如
closing
在边缘总是有问题。在你的例子中,这很容易解决:只需处理比平铺稍大的子图像,并在拼接时保留好的部分。在相关问题 更多 >
编程相关推荐