The SciPy ndimage.morphology module
The SciPy ndimage.morphology
module also provides the previously discussed functions for morphological operations on binary and grayscale images, and a few of them are demonstrated in the following sections.
Filling holes in binary objects
This function fills the holes in binary objects. The following code block demonstrates the application of the function with different structuring element sizes on an input binary image:
from scipy.ndimage.morphology import binary_fill_holes im = rgb2gray(imread('../images/text1.png')) im[im <= 0.5] = 0 im[im > 0.5] = 1 pylab.figure(figsize=(20,15)) pylab.subplot(221), pylab.imshow(im), pylab.title('original', size=20),pylab.axis('off') i = 2 for n in [3,5,7]: pylab.subplot(2, 2, i) im1 = binary_fill_holes(im, structure=np.ones((n,n))) pylab.imshow(im1), pylab.title('binary_fill_holes with structure square side ' + str(n), size=20) pylab.axis('off') i += 1 pylab.show()
The following screenshot shows...