- Introduced by
- Jean Serra
- Year
- 1982
- Type
- Set theory and topological image processing
- Family
- Image filtering and processing
What does it do?
Morphological image processing is a technique based on set theory that reshapes and analyzes image regions using geometric structuring elements.
Mathematical morphology was established in 1964 by Georges Matheron and Jean Serra, and Serra's 1982 book is a key reference for the field. Core operations include erosion and dilation, which can be combined into more complex operations like opening and closing, enabling noise removal, edge detection, and object analysis.
The intuition behind the method
Morphological operations treat images as sets of pixels and apply operations based on shape and topology. A structuring element (a small template of arbitrary shape) is used to probe the image: dilation expands bright regions by adding pixels where the structuring element overlaps any bright pixel; erosion shrinks bright regions by removing pixels where the structuring element does not fit entirely within bright regions. These basic operations can be combined: opening (erosion followed by dilation) removes small noise while preserving object shape; closing (dilation followed by erosion) fills holes and joins nearby objects.
History
Mathematical morphology was established in 1964 by Georges Matheron and Jean Serra as a branch of image processing that describes shapes using set theory. Serra's 1982 book Image Analysis and Mathematical Morphology is a key reference for the field. Haralick and co-authors (1987) published a tutorial reviewing binary and grayscale morphology, covering dilation, erosion, opening and closing and the relations between them. The tutorial argues that morphological operators relate directly to shape, which makes them useful for identifying objects and defects in industrial vision.
When to use it
Use morphological operations on binary masks, for example after thresholding, when the task is shape-driven: removing speckle noise (opening), filling holes or bridging small gaps (closing), separating touching objects, or extracting boundaries (morphological gradient). They suit cases where the objects of interest differ from the background in shape rather than in texture. Do not expect them to separate objects that differ only in intensity or texture; the operations act on the spatial arrangement of foreground pixels, so thresholding or another segmentation step must come first. Grayscale versions exist, and the cited 1987 tutorial reviews them, but binary input is the simplest and most common case.
Limitations and considerations
- Binary operations require a binary foreground, so the result is only as good as the thresholding that produced the mask; a poor threshold carries through every subsequent operation.
- The structuring element is a fixed choice made by the user; its shape and size decide which features survive, so the same image can give different outcomes with different elements.
- Features thinner or smaller than the element are removed by opening, which can erase legitimate fine structures such as thin branches or small objects.
- Because the operators use only shape and spatial arrangement, objects that differ from the background in intensity or texture but share a similar shape cannot be distinguished by morphology alone.
- The outcome depends on the order of operations and on the reference pixel (origin) of the structuring element. Opening followed by closing and closing followed by opening generally give different results, and for an asymmetric element a change of origin shifts the output. State both choices and check them on test images.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Each output pixel depends only on the pixels under the structuring element, so the effect is determined by the element's shape and size and can be anticipated before the operation is run.
- Opening and closing act on shape: opening removes features that cannot contain the element, and closing fills background gaps narrower than the element, which is the basis for noise removal and hole filling.
- The operators relate directly to shape, which the cited tutorial argues makes them more useful than convolution for identifying objects and defects in industrial vision.
- Both binary and grayscale formulations exist, so the same erosion, dilation, opening and closing operations apply beyond strictly binary input.
Applications
- Binary image cleanup: removing noise and filling holes in binarized documents or medical images
- Object separation: splitting touching objects for individual analysis or counting, for example by sequential erosion
- Boundary extraction: computing morphological gradients (dilation minus erosion) to obtain outline maps of binary objects
- Document image analysis: cleaning up text images and separating text from background
- Medical image preprocessing: preparing binary segmentations for analysis or visualization
How it works
How it works
Define a structuring element (kernel), typically a small binary image of a specific shape (rectangular, circular, diamond).
No parameters are learned in this step. For erosion, slide the structuring element over the binary image and set output pixels to 1 only if the structuring element fits entirely in the foreground. For dilation, set output pixels to 1 if the structuring element overlaps any foreground pixel.
Combine erosion and dilation into derived operations. Opening (erosion then dilation) removes foreground features that cannot contain the structuring element, and closing (dilation then erosion) fills background gaps that the element cannot fit through. Apply the operations iteratively or in sequence to reach the desired effect; the output is determined entirely by the chosen element and the order of operations.
Assess the result by inspecting boundary placement, whether holes were filled or small components removed as intended, and whether thin structures were lost. Compare the output against the original image or a reference mask using an overlap measure such as the Dice coefficient or intersection-over-union. Check border handling as well: erosion and dilation near the image edge depend on how pixels outside the image are treated, so state the padding convention used. Report the structuring element, its origin and the order of operations together with the result. Because no parameters are fitted, evaluation checks the chosen element, padding and operation order rather than a trained model.
Common pitfalls
- Choosing the element size arbitrarily; it should be matched to the size of the noise or features to be removed or preserved, and checked on representative images.
- Applying morphology to a poorly thresholded mask; the operations cannot recover foreground that thresholding has already lost.
- Stacking many erosions and dilations; repeated erosion can break thin connections and separate objects that should remain joined.
- Assuming the operations preserve area or perimeter; opening and closing change these measurements, so quantitative measurements taken after morphological filtering must account for that.
Frequently asked questions
What is the difference between erosion and dilation?
Erosion shrinks bright (foreground) regions: output pixels are set to 1 only if the entire structuring element fits within the foreground. Dilation expands bright regions: output pixels are set to 1 if the structuring element overlaps any foreground pixel. Erosion removes small features; dilation fills small holes. They are opposite operations in effect.
When should I use opening versus closing?
Opening (erosion then dilation) removes small foreground objects and noise while preserving larger object shapes. Use opening to clean up binary images with noise. Closing (dilation then erosion) fills small holes and connects nearby objects while preserving overall shape. Use closing to fill interior voids or merge nearby objects. Together, opening and closing form a complete morphological filter.
How do I choose the right structuring element size?
Choose the element so that its size is comparable to the features you want to remove or keep. For noise removal, an element slightly larger than the noise speckles removes them under opening; a smaller element leaves finer details intact. The appropriate size depends on the image and should be checked visually on representative examples. For edge (morphological gradient) maps, a small element is usually enough because the gradient measures change over a small neighbourhood.
Can morphological operations be applied to grayscale images?
Yes. Grayscale morphology operates on the grayscale values directly, generalising the min (erosion) and max (dilation) operations to all pixel values. Grayscale erosion replaces each pixel with the minimum in the structuring element neighbourhood; grayscale dilation uses the maximum. Applying grayscale morphology gives different results from thresholding to a binary mask first and then applying binary operations, so the choice between them should follow the task.
Related methods
Sources
Serra, J. (1982). Image Analysis and Mathematical Morphology. Academic Press.
Open publication referenceHaralick, R. M., Sternberg, S. R., & Zink, X. (1987). Image analysis using mathematical morphology. IEEE Transactions on Pattern Analysis and Machine Intelligence, 9(4), 532–550.
Open DOI reference