如何使用skimage完全填充图像的孔?

Kim*_*Hee 1 image-processing python-2.7 scikit-image

我正在使用skimage填充二进制输入图像(左侧)的孔。这是我的代码

在此处输入图片说明

from skimage import ndimage
img_fill_holes=ndimage.binary_fill_holes(binary).astype(int)
Run Code Online (Sandbox Code Playgroud)

但是,以上代码的结果无法完全填补二进制图像的空白。这意味着输出仍然保留圆内的孔。如何完全填充圆孔?

use*_*345 5

您可能已尝试将其应用于binary_fill_holesRGB图像(3D矩阵,请binary.shape[2] == 3进行检查)。

尝试:

img_fill_holes = ndimage.binary_fill_holes(binary[:,:,0]).astype(int)
Run Code Online (Sandbox Code Playgroud)

或任何其他“ rgb2gray”方法,您应该获得预期的输出

  • 我刚试过这个,在`skimage`中似乎没有`ndimage`子包。我尝试导入`skimage.ndimage`,它说没有这样的包。然而,我确实在 SciPy 中找到了它:https://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.ndimage.morphology.binary_fill_holes.html 并且输入和输出是相同的。 (2认同)