Preliminaries
Morphology provides a unified and robust approach to many image processing problems. The foundation of mathematical morphology is set theory.
We will focus on thresholded images, which consist only of black and white pixels. The complete morphological description of such an image is contained within the “set of white pixels”. These sets are subsets of , where each vector represents the coordinates of a white (or black) pixel.
Set Translation
The translation of a set by a point , denoted as , is defined as:
Explanation:
If represents a set of pixels forming an object in an image, is the set of points in where the coordinates are shifted by . In simpler terms, every point in is moved by the same amount, defined by .
Set Reflection
The reflection of a set , denoted as , is defined as:
Explanation: The reflection of consists of points whose coordinates are replaced with . Geometrically, this flips the set across both the x and y axes, relative to the origin.
Structuring Elements
Morphological operations rely on structuring elements (SEs).
Definition: SEs are small sets or subimages used to analyze an image and extract specific properties of interest.
- SEs are typically small.
- They “probe” the image.
- Non-rectangular SEs are often padded with background values (zeros).
- The center of the SE is an important reference point.
Erosion
Given sets and in , the erosion of by , denoted as , is defined as:
Explanation:
The erosion of by is the set of all points such that when is translated by , it is completely contained within . Another way to express the condition is: the intersection of the translated , , and the complement of , denoted as , is empty. This means no part of the translated structuring element falls outside of set A.
Erosion Example:
(Illustrative examples from the PDF are described here)
- A rectangular region () is eroded by a smaller square structuring element ().
- Points where the translated overlaps with the complement of are removed.
- The resulting eroded image is smaller than the original.
- The size of eroded region shrinks as the structuring element increases in dimension.
Dilation
Given sets and in , the dilation of by , denoted as , is defined as:
Explanation:
The dilation of by is the set of all displacements, , such that the reflection of (i.e., ), translated by , overlaps with by at least one element. This is analogous to spatial convolution. The structuring element is reflected and then moved across the image .
Dilation Example:
(Illustrative examples from the PDF are described here)
- Dilation can bridge gaps in text.
- A simple structuring element with 1s in the center cross and 0s elsewhere is used.
Opening and Closing
Given an image and a structuring element :
Opening:
- Erosion followed by dilation.
- Smoothes the contour of an object.
- Breaks narrow connections (isthmuses).
- Eliminates thin protrusions.
Closing:
- Dilation followed by erosion.
- Smoothes sections of contours.
- Fuses narrow breaks and long, thin gulfs.
- Eliminates small holes.
- Fills gaps in the contour.
Opening and Closing Example (Fingerprint):
- Opening: Removes noise but creates holes. Subsequent dilation partially closes the induced holes.
- Closing: Restores breaks in the ridges but thickens them. Subsequent Erosion thins the ridges.
- Sequence: Opening followed by closing eliminates noise and closes breaks caused by imperfect thresholding.
Hole Filling
A hole is a background region surrounded by a connected border of foreground pixels.
Procedure:
- Let be an array of the same size as , initialized with 0s except for a seed point inside the hole, which is set to 1.
- Iteratively apply the following: Where is a suitable structuring element (e.g., a cross).
- The iteration continues until .
- The union between and gives the filled hole.
Explanation:
The procedure starts from a point inside the hole and iteratively dilates it. The intersection with the complement of () prevents the dilation from extending beyond the boundaries of the hole (defined by the foreground pixels of ).
Connected Components
Similar to hole filling, but the intersection is performed with instead of .
Procedure:
- Let be an array the same size as , filled with 0s except for a known point within the connected component, which is set to 1.
- Iteratively apply: Where is a structuring element.
- The iteration stops when .
Explanation:
This iteratively expands a seed point within a connected component. The intersection with confines the expansion to the connected component.
Boundary Extraction
The boundary of a set , denoted as , can be obtained by:
Explanation:
First, is eroded by . Then, the set difference between the original and its erosion is calculated. This leaves only the boundary pixels.
Moore Boundary Tracking
The Moore boundary tracking algorithm extracts an ordered sequence of foreground boundary points.
Assumptions:
- Binary thresholded images (0: background, 1: foreground).
- Images are padded with 0s to prevent foreground regions from touching the image border.
Algorithm:
-
Initialization:
- : The uppermost, leftmost point in the image labeled 1.
- : The west neighbor of .
- Examine the 8-neighbors of starting from in a clockwise direction.
- : The first neighbor encountered with a value of 1.
- : The background point immediately preceding .
-
Iteration:
- , .
- Let be the 8-neighbors of , starting from and proceeding clockwise.
- Find the first labeled 1.
- , .
-
Termination:
- Repeat steps 2 and previous until and the next boundary point found is .
- The sequence of points found constitutes the ordered boundary.
Gray-Scale Morphology
So far, we’ve dealt with binary images. Morphological operations can also be defined for grayscale images.
- (grayscale image)
- (structuring element)
The structuring element, , acts as a “probe” to examine the image. It can be non-flat or flat (more common).
Gray-Scale Erosion
The erosion of by a flat structuring element at location is:
Explanation:
It’s the minimum value of the image within the region defined by when the origin of is at . Conceptually similar to convolution, but using the minimum operation.
Gray-Scale Dilation
The dilation of by a flat structuring element at location is:
Explanation: It’s the maximum value of the image within the region defined by the reflection of , with the origin of reflection of at . The negative signs in the equation account for the reflection of the structuring element.
Effect of Erosion and Dilation (Grayscale)
- Erosion: The resulting image is darker, and bright features are reduced in size.
- Dilation: The resulting image is brighter, bright features are thickened, and dark features are reduced.
Gray-Scale Opening and Closing
The expressions are the same as for the binary case:
- Opening:
- Closing:
Geometric Interpretation:
Imagine and as 3D surfaces.
- Opening: Pushing the structuring element up from below against the undersurface of .
- Closing: Pushing the structuring element down from the top of the surface of .
Effect of Opening and Closing (Grayscale)
- Opening: Attenuate bright features, negligible on dark.
- Closing: Attenuate dark features, negligible on bright.
Morphological Smoothing
Opening suppresses bright details, and closing suppresses dark details. They are often combined for smoothing and noise removal.
Morphological Gradient
Explanation:
The difference between dilation and erosion emphasizes boundaries between regions. Edges are enhanced, and homogeneous areas are suppressed, resulting in a “derivative-like” (gradient) effect.
Top-Hat and Bottom-Hat Transformations
- Top-Hat:
- minus its opening.
- Bottom-Hat:
- Closing of minus .
Goal: Select objects by using a structuring element that does not fit the objects to be removed. The difference then isolates the selected objects.
Top-Hat for Illumination Correction:
Top-hat can help correct uneven illumination.
- Original image with uneven illumination.
- Opening with a large structuring element (e.g., 40x40 disc) to estimate the background illumination.
- Top-hat (Original - Opening) to isolate the objects on a more uniform background.
- Applying Otsu thresholding after Top-hat correction leads to better results.