The following few code blocks show how to apply the morphological operations on grayscale images. First, let's start with gray-level erosion:
from skimage.morphology import dilation, erosion, closing, opening, squareim = imread('../images/zebras.jpg')im = rgb2gray(im)struct_elem = square(5) eroded = erosion(im, struct_elem)plot_images_horizontally(im, eroded, 'erosion')
The following screenshot shows the output of the previous code block. As can be seen, the black stripes are widened with erosion:
The following code block shows how to apply dilation on the same input grayscale image:
dilated = dilation(im, struct_elem) ...