![]() |
VOOZH | about |
Morphological operations process images based on the arrangement of neighboring pixels. Erosion and dilation are two fundamental techniques used to modify object boundaries, remove noise, fill gaps, and refine shapes in binary and grayscale images.
Erosion shrinks foreground regions by removing pixels from object boundaries. It is commonly used to eliminate small white noise, separate connected objects, and reduce the size of foreground features in an image.
Code Implementation:
Used image can be downloaded from here.
cv2.erode() to remove pixels from object boundaries, reducing the size of foreground regions and eliminating small white noise. Output:
The output image contains thinner foreground regions because pixels along object boundaries are removed.
Dilation expands foreground regions by adding pixels to object boundaries. It is commonly used to fill small gaps, connect nearby objects, and enhance the visibility of foreground features.
Code Implementation:
cv2.dilate() to add pixels around object boundaries, increasing the size of foreground regions and filling small gaps. Output:
The output displays the original image alongside the dilated image, where foreground regions appear larger due to the addition of boundary pixels.
| Feature | Erosion | Dilation |
|---|---|---|
| Main Purpose | Shrinks foreground objects | Expands foreground objects |
| Visual Effect | Objects appear smaller and thinner | Objects appear larger and thicker |
| Edge Behavior | Removes pixels from object boundaries | Adds pixels to object boundaries |
| Noise Handling | Removes small white noise and unwanted details | Fills small gaps and holes in objects |
| Applications | Noise removal, object separation, boundary refinement | Gap filling, object enhancement, object connection |