Search code examples
python-2.7image-processingscikit-image

How to completely fill holes to an image using the skimage?


I am using skimage to fill holes a binary input image (left side). This is my code

enter image description here

from skimage import ndimage
img_fill_holes=ndimage.binary_fill_holes(binary).astype(int)

However, the result of the above code cannot completely fill holes to the binary image. It means the output still remains the holes inside the circle. How can I completely fill all holes inside the circle?


Solution

  • you were probably tried to apply binary_fill_holes on an RGB image (a 3D matrix, do binary.shape[2] == 3 to check that).

    try:

    img_fill_holes = ndimage.binary_fill_holes(binary[:,:,0]).astype(int)
    

    or any other "rgb2gray" approach and you should get the expected output