Opening and closing can be sequentially used to remove noise (small foreground objects) from a binary image. This can be used in cleaning a fingerprint image as a preprocessing step. The following code block demonstrates how to implement it:
im = rgb2gray(imread('../images/fingerprint.jpg'))im[im <= 0.5] = 0 # binarizeim[im > 0.5] = 1im_o = binary_opening(im, square(2))im_c = binary_closing(im, square(2))im_oc = binary_closing(binary_opening(im, square(2)), square(2))pylab.figure(figsize=(20,20))pylab.subplot(221), plot_image(im, 'original')pylab.subplot(222), plot_image(im_o, 'opening')pylab.subplot(223), plot_image(im_c, 'closing')pylab.subplot(224), plot_image(im_oc, 'opening + closing')pylab.show() ...