Grayscale operations

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) ...

Get Hands-On Image Processing with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.