| Customize Help

Erosion and dilation



Especially during cell analysis, it can be important to know the growth stages of cell particles. Using the image processing erosion and dilation operations, you can view the possible growth stages of these particles.

  • Erosion operations peel off layers from objects or particles, removing extraneous pixels and small particles from the image.

  • Dilation operations add layers to objects or particles, enlarging any particle. Dilation can return eroded particles to their original size (but not necessarily to their exact original shape).

Erosion and dilation are neighborhood operations that determine each pixel's value according to its geometric relationship with neighborhood pixels, and as such, are part of a group of operations known as morphological operations. This section describes basic erosion and dilation performed using MimErode() and MimDilate(). Both these functions use predefined kernels to perform operations. For a description of advanced erosion and dilation, performed by MimMorphic(), see the Custom morphological operations section of Chapter 4: Advanced image processing.

They are also the basic operations used to perform the opening and closing operations discussed in the following section.

Note, zero pixels are considered background, while non-zero pixels are considered foreground and part of objects (more generally referred to as blobs).

Erosion

You can perform a basic erosion operation on 3 by 3 neighborhoods, using MimErode() with one of the following two options:

  • If the erosion mode is set to M_BINARY, any pixel whose neighborhood is not completely white (any non-zero pixel is considered white) is changed to black (0 is considered black).

  • If the erosion mode is set to M_GRAYSCALE, each pixel is replaced with the minimum value in its neighborhood.

You can use the iteration parameter of MimErode() to perform an erosion on larger neighborhoods. Iterating the erosion is the equivalent to performing an erosion on a (1 + (2* i)) by (1 + (2* i)) neighborhood where i is the number of iterations. For example, two iterations of a 3x3 erosion is equivalent to a 5x5 erosion, and three iterations is equivalent to a 7x7 erosion.

If you need to iterate a binary erosion on each blob until it is about to disappear, set the erosion mode to M_BINARY_ULTIMATE or M_BINARY_ULTIMATE_ACCUMULATE instead of M_BINARY, and set the iteration parameter to M_DEFAULT. M_BINARY_ULTIMATE_ACCUMULATE also keeps track of the number of iterations that occurred for each pixel that is not eroded.

The following animation illustrates an example of MimErode() with M_BINARY_ULTIMATE (on the left) and M_BINARY_ULTIMATE_ACCUMULATE (on the right).

Dilation

You can perform a basic dilation operation on 3 by 3 neighborhoods, using MimDilate() with one of the following two options:

  • If the dilation mode is set to M_BINARY, any pixel that has one or more white pixels (any non-zero pixel is considered white) in its neighborhood is set to white (0xff in an 8-bit image).

  • If the dilation mode is set to M_GRAYSCALE, each pixel is replaced with the maximum value in its neighborhood.

The MimDilate() function is similar to the MimErode() function in that iterating it will effectively cause a dilation on larger neighborhoods. Iterating the dilation is the equivalent to performing a dilation on a (1 + (2* i)) by (1 + (2* i)) neighborhood where i is the number of iterations. For example, two iterations of a 3x3 dilation is equivalent to a 5x5 dilation, and three iterations is equivalent to a 7x7 dilation.

The following animation demonstrates the use of MimDilate() with a fixed number of iterations. The characters in the following animation are composed of dots. After four iterations, the characters are made up of solid lines and can be identified more easily.

If you need to iterate a binary dilation on each blob until its holes and background are about to disappear, set the dilation mode to M_BINARY_ULTIMATE instead of M_BINARY, and set the iteration parameter to M_DEFAULT. If you need to keep track of the number of iterations that occurred for each remaining background or hole pixel during dilation, set the dilation mode to M_BINARY_ULTIMATE_ACCUMULATE instead. This will take the negative of the image (white pixels will become black and black pixels will become white) and then performs an erosion on the new blobs (on the new white pixels).

The following animation illustrates an example of MimDilate() with M_BINARY_ULTIMATE (on the left) and M_BINARY_ULTIMATE_ACCUMULATE (on the right).

An example

You can use erosion or dilation to find the perimeter of objects. Erode or dilate a binary image and `XOR' the result with the original image, using MimArith().

The following example shows how to obtain the exoskeletons of objects in an image.