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, square
im = 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)
plot_images_horizontally(im, dilated, 'dilation')

The following screenshot shows the output of the previous code block. As can be seen, the black stripes are narrowed down with dilation:

The following code block shows how to apply the morphological gray-level opening operation on the same input grayscale image:

opened = opening(im, struct_elem)
plot_images_horizontally(im, opened, 'opening')

The following screenshot shows the output. As can be seen, the width of the black stripes did not change with opening, although some thin white stripes were removed:

The following code block shows how to apply the morphological gray-level closing operation on the same input grayscale image:

closed = closing(im, struct_elem)
plot_images_horizontally(im, closed, 'closing')

The following screenshot shows the output. As can be seen, the width of the white stripes did not change with closing, although some thin black stripes were removed:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.126.5