Dilation and Erosion

Dilation enlarges light objects in an image (regardless of whether you use positive or negative offset values). Dilation eliminates small dark gaps and holes and enlarges lighter features such as thin lines and fine detail.

Erosion shrinks light objects in an image (regardless of whether you use positive or negative offset values). Erosion eliminates lighter features such as thin lines, fine detail, and small islands, and enlarges dark holes and gaps.

In a morphological operation, the origin pixel of the structuring element is superimposed on a pixel in the source image.

  • For a dilation operation, the offset value at each pixel location in the structuring element is added to the value of its corresponding pixel in the source image. This yields a sum for each pixel location in the structuring element. The result is the maximum of these sums.
  • For an erosion operation, the offset value at each pixel location in the structuring element is subtracted from the value of its corresponding pixel in the source image. This yields a difference for each pixel location in the structuring element. The result is the minimum of these differences.

For both dilation and erosion, the result is stored at the pixel in the destination image corresponding to the structuring element’s origin. The operation is repeated for each location in the source image.

The figure below shows an example of a 3x3 dilation. The bold square in the source image denotes the source pixel being operated upon; the bold square in the structuring element denotes its origin. The result of the morphological operation is written to the corresponding pixel in the destination image. (Note in the figure below that the operation uses the reflected structuring element; this is explained in the section Reflection of Structuring Elements.)

Example of a 3x3 dilation for a single destination pixel

The figure below shows an example of a 3x3 erosion.

Example of a 3x3 erosion for a single destination pixel

The figure below shows the effects of dilation and erosion using a simple 3 x 3 structuring element on an input image.

Sample erosion and dilation