Help
What are Morphological Operations?
Morphological operations are image processing techniques that process images based on shapes. They work by applying a structuring element to an image. The main operations are:
- Erosion: Shrinks white regions, removes small white noise, separates objects
- Dilation: Expands white regions, fills small holes, connects nearby objects
- Opening: Erosion followed by dilation - removes small objects while preserving shape
- Closing: Dilation followed by erosion - fills small holes while preserving shape
Structuring Elements
- Square: Standard rectangular kernel, processes in all directions equally
- Cross: Plus-shaped kernel, emphasizes horizontal and vertical directions
- Circle: Circular kernel approximation, isotropic (direction-independent)
- Size: Larger kernels produce stronger effects but may lose fine details
How Erosion Works
Erosion sets a pixel to white (255) only if ALL pixels under the structuring element are white. Otherwise, it becomes black (0).
This causes white regions to shrink from the edges, removing small protrusions and thin connections.
How Dilation Works
Dilation sets a pixel to white (255) if ANY pixel under the structuring element is white. Otherwise, it stays black (0).
This causes white regions to expand, filling small gaps and connecting nearby objects.
Common Applications
- Noise Removal: Use opening to remove small white noise
- Hole Filling: Use closing to fill small black holes in white regions
- Edge Detection: Subtract eroded image from original
- Object Separation: Use erosion to separate touching objects
- Feature Extraction: Extract specific shapes or patterns
Tips for Best Results
- Adjust the threshold to create a clean binary image first
- Start with a small structuring element (3x3) and increase if needed
- Opening is good for removing small bright spots on dark backgrounds
- Closing is good for removing small dark spots on bright backgrounds
- Multiple operations can be chained for complex processing