Grayscale Morphology
- Updated2025-11-25
- 6 minute(s) read
Morphological transformations extract and alter the structure of particles in an image. They fall into two categories:
- Binary morphology functions, which apply to binary images.
- Grayscale morphology functions, which apply to gray-level images.
In grayscale morphology, a pixel is compared to those pixels surrounding it in order to keep the pixels whose values are the smallest (in the case of an erosion) or the largest (in the case of a dilation).
When to Use
Use grayscale morphology functions to filter or smooth the pixel intensities of an image. Applications include noise filtering, uneven background correction, and gray-level feature extraction.
Concepts
The gray-level morphology functions apply to gray-level images. You can use these functions to alter the shape of regions by expanding bright areas at the expense of dark areas and vice versa. These functions smooth gradually varying patterns and increase the contrast in boundary areas. This section describes the following gray-level morphology functions:
- erosion,
- dilation,
- opening,
- closing,
- proper-opening,
- proper-closing,
- auto-median.
These functions are derived from the combination of gray-level erosions and dilations that use a structuring element.
Erosion Function
A gray-level erosion reduces the brightness of pixels that are surrounded by neighbors with a lower intensity. The neighborhood is defined by a structuring element.
Dilation Function
A gray-level dilation increases the brightness of each pixel that is surrounded by neighbors with a higher intensity. The neighborhood is defined by a structuring element. The gray-level dilation has the opposite effect of the gray-level erosion because dilating bright regions also erodes dark regions.
Erosion and Dilation Examples
This example uses the following source image.
The following table provides example structuring elements and the corresponding eroded and dilated images
Opening Function
The gray-level opening function consists of a gray-level erosion followed by a gray-level dilation. It removes bright spots isolated in dark regions and smooths boundaries. The effects of the function are moderated by the configuration of the structuring element.
opening(I) = dilation(erosion (I))
This operation does not significantly alter the area and shape of particles because erosion and dilation are morphological opposites. Bright borders reduced by the erosion are restored by the dilation. However, small bright particles that vanish during the erosion do not reappear after the dilation.
Closing Function
The gray-level closing function consists of a gray-level dilation followed by a gray-level erosion. It removes dark spots isolated in bright regions and smooths boundaries. The effects of the function are moderated by the configuration of the structuring element.
closing(I) = erosion(dilation (I))
This operation does not significantly alter the area and shape of particles because dilation and erosion are morphological opposites. Bright borders expanded by the dilation are reduced by the erosion. However, small dark particles that vanish during the dilation do not reappear after the erosion.
Opening and Closing Examples
This example uses the following source image.
The opening function produces the following image.
A closing function produces the following image.
Proper-Opening Function
The gray-level proper-opening function is a finite and dual combination of openings and closings. It removes bright pixels isolated in dark regions and smooths the boundaries of bright regions. The effects of the function are moderated by the configuration of the structuring element.
Proper-Closing Function
The proper-closing function is a finite and dual combination of closings and openings. It removes dark pixels isolated in bright regions and smooths the boundaries of dark regions. The effects of the function are moderated by the configuration of the structuring element.
Auto-Median Function
The auto-median function uses dual combinations of openings and closings. It generates simpler particles that have fewer details.
Erosion Concept and Mathematics
Each pixel in an image becomes equal to the minimum value of its neighbors.
For a given pixel P0, the structuring element is centered on P0.
The pixels masked by a coefficient of the structuring element equal to 1 are then referred as Pi.
A gray-level erosion using a structuring element f × f with all its coefficients set to 1 is equivalent to an Nth order filter with a filter size f × f and the value N equal to 0. Refer to the nonlinear filters section for more information.
Dilation Concept and Mathematics
Each pixel in an image becomes equal to the maximum value of its neighbors.
For a given pixel P0, the structuring element is centered on P0.
The pixels masked by a coefficient of the structuring element equal to 1 are then referred as Pi.
Proper-Opening Concept and Mathematics
If I is the source image, the proper-opening function extracts the minimum value of each pixel between the source image I and its transformed image obtained after an opening, followed by a closing, and followed by another opening.
or
where:
- I is the source image,
- E is an erosion,
- D is a dilation,
- O is an opening,
- C is a closing,
- F(I) is the image obtained after applying the function F to the image I,
- GF(I) is the image obtained after applying the function F to the image I followed by the function G to the image I.
Proper-Closing Concept and Mathematics
If I is the source image, the proper-closing function extracts the maximum value of each pixel between the source image I and its transformed image obtained after a closing, followed by an opening, and followed by another closing.
or
where:
- I is the source image,
- E is an erosion,
- D is a dilation,
- O is an opening,
- C is a closing,
- F(I) is the image obtained after applying the function F to the image I,
- GF(I) is the image obtained after applying the function F to the image I followed by the function G to the image I.
Auto-Median Concept and Mathematics
If I is the source image, the auto-median function extracts the minimum value of each pixel between the two images obtained by applying a proper-opening and a proper-closing of the source image I.
or
where:
- I is the source image,
- E is an erosion,
- D is a dilation,
- O is an opening,
- C is a closing,
- F(I) is the image obtained after applying the function F to the image I,
- GF(I) is the image obtained after applying the function F to the image I followed by the function G to the image I.