5. Image Enhancement: Erosion & Dilation of image
Aim:
To study and implement the fundamental morphological operations—Erosion and Dilation—for
image enhancement and analysis in MATLAB.
Objectives:
• To understand the concepts of morphological image processing.
• To implement and analyse the effect of:
1.
Erosion
2.
Dilation
3.
Combination of Erosion and Dilation (Opening & Closing)
• To compare the outputs for different structuring element sizes and shapes.
• To apply these operations to practical image analysis tasks.
Theory:
1. Introduction to Morphological Processing
•
Morphological image processing is a collection of non-linear operations related to the shape or
morphology of features in an image.
•
These operations process images based on shapes. They apply a structuring element to an input
image, creating an output image of the same size.
•
Morphology is most commonly applied to binary images (black and white), but it can also be used
on grayscale images.
•
The two most basic morphological operations are Erosion and Dilation. All other morphological
operations are built from these two.
2. Morphological Operations – Concept
•
A structuring element (SE) is a small matrix or kernel (e.g., 3x3, 5x5) with a defined shape (e.g.,
square, disk, line) and an origin (usually the centre).
•
The structuring element is convolved with the image. The output pixel's value is based on a
comparison of the SE with the corresponding neighbourhood of pixels.
Key Definitions:
•
Binary Image: An image where each pixel is either 0 (Black/Background) or 1
(White/Foreground).
•
Structuring Element (SE): A small pattern used to probe the image.
3. Types of Basic Morphological Operations
(a) Erosion
•
Erosion shrinks or thins objects in a binary image.
•
The value of the output pixel is 1 (white) only if every pixel under the structuring element is 1.
Otherwise, the output pixel is set to 0 (black).
Effect:
•
Removes small isolated objects (e.g., noise).
•
Disconnects weakly connected objects.
•
Erodes the boundaries of larger objects, making them smaller.
Real-Life Analogy:
•
Imagine erosion in geology: water and wind wear away the boundaries of land, making rocks
smaller and smoothing coastlines.
•
In image terms, it's like rubbing away the outer layer of a white object on a black canvas.
(b) Dilation
•
Dilation expands or thickens objects in a binary image.
•
The value of the output pixel is 1 (white) if any pixel under the structuring element is 1.
Effect:
•
Fills in small holes and gaps within objects.
•
Connects nearby objects that are separated by small gaps.
•
enlarges the boundaries of larger objects, making them bigger.
Real-Life Analogy:
•
Imagine adding layers of paint to an object, causing it to expand slightly and potentially merge
with other painted objects nearby.
•
It's the opposite of erosion; it adds a layer around the white objects.
The interaction between Erosion and Dilation is powerful and leads to more complex
operations.
(c) Opening
•
Opening is the process of erosion followed by dilation.
•
It uses the same structuring element for both operations.
Formula:
Where:
•
A is the input image.
•
B is the structuring element.
•
⊖ denotes erosion.
•
⊕ denotes dilation.
Effect:
•
Removes small objects and thin protrusions from the foreground.
•
Smoothest the contours of objects.
•
"Opening is like applying erosion to remove small stuff, then dilating to restore the size of
the remaining objects."
Application:
•
Perfect for removing "salt" noise (white spots on a dark background) from an image.
(d) Closing
•
Closing is the process of dilation followed by erosion.
•
It uses the same structuring element for both operations.
Formula:
Effect:
•
Fills small holes and gaps within foreground objects.
•
Connects nearby objects and smooths contours by filling lakes.
•
"Closing is like applying dilation to fill holes, then eroding to restore the shape of the
objects."
Application:
•
Perfect for removing "pepper" noise (black spots on a white background) and filling gaps in
objects.
4. Structuring Elements
The choice of Structuring Element (SE) is critical as it defines the neighborhood used for
processing.
Common Shapes in MATLAB:
•
'square' - A square of a specified size.
•
'disk' - A circular disk of a specified radius.
•
'diamond' - A diamond-shaped element.
•
'line' - A linear segment at a specified angle.
•
'arbitrary' - A custom matrix you define.
Example of a 3x3 Square SE:
Example of a 5x5 Disk SE (approximation):
The size and shape of the SE determine the degree and nature of the morphological effect. A larger
SE will cause more aggressive erosion/dilation.
5. Applications of Morphological Operations
1. Noise Removal: Opening to remove salt noise, closing to remove pepper noise.
2. Object Segmentation: Separating touching objects or filling holes to make objects whole for
counting.
3. Feature Extraction: Isolating specific shapes or structures within an image (e.g., detecting
lines, removing irrelevant details).
4. Medical Imaging: Extracting boundaries of cells or tissues, filling holes in segmented organs.
5. Automated Inspection: Checking for breaks in circuits or cracks in materials.
6. OCR (Optical Character Recognition): Cleaning up scanned documents before character
recognition.
Apparatus / Software Required:
•
MATLAB R2021a or later (Image Processing Toolbox).
•
Computer with minimum 4 GB RAM.
•
Sample binary or grayscale images (e.g., text.png, circles.png).
Procedure / Algorithm:
•
Step 1 → Start MATLAB and set the Current Folder to your working directory.
•
Step 2 → Load or create an input image (preferably binary).
•
Step 3 → Define a structuring element (SE) of a specific shape and size.
•
Step 4 → Apply morphological operations one by one:
o
Erosion
o
Dilation
o
Opening (Erosion then Dilation)
o
Closing (Dilation then Erosion)
•
Step 5 → Display and save the results for each technique.
•
Step 6 → Compare the outputs for different SE sizes.
•
Step 7 → Note observations on the effect of each operation.