Basic processes in the realm of morphological image processing include dilation and erosion. Although they can also process grayscale images, they are mostly employed to process binary images. In order to create an output image, a structuring element interacts with the input image in both operations.
Dilation
Dilation enlarges an image's object boundaries by adding pixels. In a binary image, it is used to enlarge or thicken objects. The structuring element regulates the growth's quantity and form.
Algorithm:
Place the structuring element on the input image.
If at least one pixel in the structuring element overlaps with a foreground pixel in the image (value 1), set the corresponding pixel in the output image to 1.
Move the structuring element over the entire image and repeat the process.
Erosion
Pixels on object borders are lost due to erosion. It thins or reduces the size of items in a binary image. The structural element regulates the shrinkage's amount and shape.
Algorithm:
Place the structuring element on the input image.
If every pixel in the structuring element overlaps with a foreground pixel in the image (value 1), set the corresponding pixel in the output image to 1. Otherwise, set it to 0.
Move the structuring element over the entire image and repeat the process.
Effect: Erosion removes small objects and separates objects that are close to each other.