Functions > Image Processing > Morphological Processing > Example: Grayscale Morphology
  
Example: Grayscale Morphology
Use the grayscale morphology functions for extracting image components. You can also describe object shapes by picking out small bright or dark features in an image.
For information on using this example, refer to About Image Processing Examples.
grey_erode
In binary erosion you use a structuring element to define a neighborhood around each pixel. In this pixel neighborhood the presence of any background pixels causes the foreground to become background. Grayscale erosion is an extension of this, where the structuring element's pixel values are subtracted from the input image's pixel values. The output is the minimum resulting pixel value within the boundary of the structuring element.
1. Create a 5 x 4 sequential matrix.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
2. Create a simple structuring element (SE).
Click to copy this expression
3. Perform grayscale erosion with the origin of the SE at (0,0).
Click to copy this expression
4. Evaluate the new matrix, which should be equal to M - 1 except at the rightmost column and bottommost row (boundary conditions).
Click to copy this expression
Click to copy this expression
5. Erode a more realistic image with a 5 x 5 centered SE.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
6. Apply the erode function to the new image.
Click to copy this expression
Click to copy this expression
7. Display the original and eroded images.
(lena.bmp)
(lena_le.bmp)
As expected, we notice that the image has darkened in general, the darker regions have expanded, and some brighter details have disappeared.
grey_dilate
In binary dilation, a structuring element is used to define a neighborhood around each pixel in which the presence of any foreground pixel causes the background to become foreground.
1. Use the same sequential matrix and structuring element (SE) as previously.
Click to copy this expression
Click to copy this expression
2. Perform grayscale dilation with the origin of the SE at (0,0).
Click to copy this expression
3. Evaluate the new matrix, which should be equal to M + 1 except the at the rightmost column and bottommost row (boundary conditions).
Click to copy this expression
Click to copy this expression
4. Apply the dilate function to the previous image.
Click to copy this expression
Click to copy this expression
5. Display the original and dilated images.
(lena.bmp)
(lena_ld.bmp)
The dilation results in an increased overall brightness, expanded bright regions, and loss of small dark details.
grey_open, gray_close
Grayscale opening and closing are defined in an analogous way to opening and closing in binary morphology; opening is grayscale erosion followed by grayscale dilation, and closing is grayscale dilation followed by grayscale erosion.
Apply grey_open and grey_close to the sequential matrix to see that they are equivalent to erosion and dilation combined.
1. Apply grayscale opening to the sequential matrix.
Click to copy this expression
2. Apply grayscale erosion to the sequential matrix, with the origin of the SE at (0,0).
Click to copy this expression
3. Apply grayscale dilation to the eroded matrix, with the origin of the SE at (0,0).
Click to copy this expression
4. Show that grayscale opening is equivalent to combined grayscale erosion and dilation.
Click to copy this expression
5. Apply grayscale closing to the sequential matrix.
Click to copy this expression
6. Apply grayscale dilation to the sequential matrix, with the origin of the SE at (0,0).
Click to copy this expression
7. Apply grayscale erosion to the dilated matrix, with the origin of the SE at (0,0).
Click to copy this expression
8. Show that grayscale closing is equivalent to combined grayscale dilation and erosion.
Click to copy this expression
9. Apply the functions to the test image L, and compare the dilated, eroded, opened, and closed images.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
(lena_ld.bmp)
(lena_le.bmp)
(lena_lc.bmp)
(lena_lo.bmp)
Grayscale opening and closing result in no overall brightness change, while dilation and erosion change the brightness. Both dilation and closing enhance bright and reduce dark features in the image, while erosion and opening enhance dark and reduce bright features.