
- SciPy - Home
- SciPy - Introduction
- SciPy - Environment Setup
- SciPy - Basic Functionality
- SciPy - Relationship with NumPy
- SciPy Clusters
- SciPy - Clusters
- SciPy - Hierarchical Clustering
- SciPy - K-means Clustering
- SciPy - Distance Metrics
- SciPy Constants
- SciPy - Constants
- SciPy - Mathematical Constants
- SciPy - Physical Constants
- SciPy - Unit Conversion
- SciPy - Astronomical Constants
- SciPy - Fourier Transforms
- SciPy - FFTpack
- SciPy - Discrete Fourier Transform (DFT)
- SciPy - Fast Fourier Transform (FFT)
- SciPy Integration Equations
- SciPy - Integrate Module
- SciPy - Single Integration
- SciPy - Double Integration
- SciPy - Triple Integration
- SciPy - Multiple Integration
- SciPy Differential Equations
- SciPy - Differential Equations
- SciPy - Integration of Stochastic Differential Equations
- SciPy - Integration of Ordinary Differential Equations
- SciPy - Discontinuous Functions
- SciPy - Oscillatory Functions
- SciPy - Partial Differential Equations
- SciPy Interpolation
- SciPy - Interpolate
- SciPy - Linear 1-D Interpolation
- SciPy - Polynomial 1-D Interpolation
- SciPy - Spline 1-D Interpolation
- SciPy - Grid Data Multi-Dimensional Interpolation
- SciPy - RBF Multi-Dimensional Interpolation
- SciPy - Polynomial & Spline Interpolation
- SciPy Curve Fitting
- SciPy - Curve Fitting
- SciPy - Linear Curve Fitting
- SciPy - Non-Linear Curve Fitting
- SciPy - Input & Output
- SciPy - Input & Output
- SciPy - Reading & Writing Files
- SciPy - Working with Different File Formats
- SciPy - Efficient Data Storage with HDF5
- SciPy - Data Serialization
- SciPy Linear Algebra
- SciPy - Linalg
- SciPy - Matrix Creation & Basic Operations
- SciPy - Matrix LU Decomposition
- SciPy - Matrix QU Decomposition
- SciPy - Singular Value Decomposition
- SciPy - Cholesky Decomposition
- SciPy - Solving Linear Systems
- SciPy - Eigenvalues & Eigenvectors
- SciPy Image Processing
- SciPy - Ndimage
- SciPy - Reading & Writing Images
- SciPy - Image Transformation
- SciPy - Filtering & Edge Detection
- SciPy - Top Hat Filters
- SciPy - Morphological Filters
- SciPy - Low Pass Filters
- SciPy - High Pass Filters
- SciPy - Bilateral Filter
- SciPy - Median Filter
- SciPy - Non - Linear Filters in Image Processing
- SciPy - High Boost Filter
- SciPy - Laplacian Filter
- SciPy - Morphological Operations
- SciPy - Image Segmentation
- SciPy - Thresholding in Image Segmentation
- SciPy - Region-Based Segmentation
- SciPy - Connected Component Labeling
- SciPy Optimize
- SciPy - Optimize
- SciPy - Special Matrices & Functions
- SciPy - Unconstrained Optimization
- SciPy - Constrained Optimization
- SciPy - Matrix Norms
- SciPy - Sparse Matrix
- SciPy - Frobenius Norm
- SciPy - Spectral Norm
- SciPy Condition Numbers
- SciPy - Condition Numbers
- SciPy - Linear Least Squares
- SciPy - Non-Linear Least Squares
- SciPy - Finding Roots of Scalar Functions
- SciPy - Finding Roots of Multivariate Functions
- SciPy - Signal Processing
- SciPy - Signal Filtering & Smoothing
- SciPy - Short-Time Fourier Transform
- SciPy - Wavelet Transform
- SciPy - Continuous Wavelet Transform
- SciPy - Discrete Wavelet Transform
- SciPy - Wavelet Packet Transform
- SciPy - Multi-Resolution Analysis
- SciPy - Stationary Wavelet Transform
- SciPy - Statistical Functions
- SciPy - Stats
- SciPy - Descriptive Statistics
- SciPy - Continuous Probability Distributions
- SciPy - Discrete Probability Distributions
- SciPy - Statistical Tests & Inference
- SciPy - Generating Random Samples
- SciPy - Kaplan-Meier Estimator Survival Analysis
- SciPy - Cox Proportional Hazards Model Survival Analysis
- SciPy Spatial Data
- SciPy - Spatial
- SciPy - Special Functions
- SciPy - Special Package
- SciPy Advanced Topics
- SciPy - CSGraph
- SciPy - ODR
- SciPy Useful Resources
- SciPy - Reference
- SciPy - Quick Guide
- SciPy - Cheatsheet
- SciPy - Useful Resources
- SciPy - Discussion
SciPy - Morphological Operations
Morphological operations are a set of image processing techniques that process images based on their shapes. They are primarily applied to binary and gray-scale images and rely on a structuring element to probe, transform and manipulate the shapes in the image.
The core concept behind the Morphological operations is set theory, where the image is treated as a set of pixels and the transformations depend on the interaction between the image and the structuring element.
Key concepts in Morphological Operations
Before proceeding with the Morphological Operations in detail, first we need to get to know the key concepts of them. Here are the key concepts of Morphological Operations in SciPy −
Image Representation
In the view of morphological operations the images are represented as arrays of pixel values. This array-based representation enables mathematical manipulations using structuring elements. SciPy and similar libraries handle images as NumPy arrays which allow efficient computations.
The images in morphological Operations can be represented in two ways as mentioned below −
- Binary Images: A binary image consists of only two pixel values as 0 and 1 or 0 and 255 in some systems. 0 represents the background i.e., black while 1 represents the foreground i.e., white.
- Grayscale Images: A grayscale image contains pixel values ranging from 0 i.e., black to 255 i.e., white. Each pixel intensity represents the brightness level of that point in the image.
Structuring Element (Kernel)
The structuring element is a small matrix or pattern that defines the neighborhood used to perform morphological operations. Its shapes like square, disk, cross determines how the operation interacts with the image and the size of the structuring element affects the scale of the transformation.
Origin
The center of the structuring element determines its alignment with the image pixels during the operation.
Core Morphological Operations
Morphological operations are fundamental techniques used in image processing for shape analysis, noise removal and feature extraction. The core operations are Erosion, Dilation, Opening and Closing. These operations rely on the use of a structuring element to probe the image. Let's see all the available Morphological operations in SciPy Image processing −
Erosion Using SciPy
Erosion shrinks the foreground i.e., bright regions of an image by removing pixels at the boundaries of objects. This Operation works as, if a pixel in the output is set to 1 or remains part of the foreground only then all pixels in the neighborhood defined by the structuring element are 1.
When we apply the Erosion operation then it reduces the size of objects, removes small white noise and disconnects joined components. We have a function as binary_erosion() in scipy.ndimage module to perform Erosion Morphological Operation in SciPy.
Following is the mathematical formula of Erosion −
AB={z(B)z A}
where A is the input image, B is the structuring element and (B)z represents the structuring element translated to position z.
Dilation Ui
Dilation grows or expands the foreground, i.e., bright regions of an image, by adding pixels to the boundaries of objects. This operation works as, if a pixel in the output is set to 1, at least one pixel in the neighborhood defined by the structuring element must be 1.
When we apply the Dilation operation, it increases the size of objects, fills small holes and connects nearby components. We have a function as binary_dilation() in scipy.ndimage module to perform Dilation Morphological Operation in SciPy.
Following is the mathematical formula of Dilation −
AB={z(B)z A }
where A is the input image, B is the structuring element and (B)z represents the structuring element translated to position z.
Opening
Opening is a combination of Erosion followed by Dilation. It works by first performing Erosion to remove small bright regions or thin details and then applying Dilation to restore the main shape of the objects.
The Opening operation smoothens the boundaries of objects, removes small bright regions and eliminates noise. We have a function as binary_opening() in scipy.ndimage module to perform Opening Morphological Operation in SciPy.
Following is the mathematical formula of Opening −
AB = (AB)B
where A is the input image and B is the structuring element.
Closing
Closing is a combination of Dilation followed by Erosion. It works by first performing Dilation to expand the boundaries of objects and then applying Erosion to restore the shape of the objects.
The Closing operation smoothens object boundaries, fills small black holes and connects broken components. We have a function as binary_closing() in scipy.ndimage module to perform Closing Morphological Operation in SciPy.
Following is the mathematical formula of Closing −
AB = (AB)B
where A is the input image and B is the structuring element.
Morphological Gradient
The Morphological Gradient highlights the boundaries of objects by subtracting the Eroded image from the Dilated image. It is useful for detecting edges or outlines of objects in an image.
The Morphological Gradient operation produces an outline of the object boundaries by comparing the effects of Dilation and Erosion. It can be implemented using functions like grey_dilation() and grey_erosion() in scipy.ndimage module.
Following is the mathematical formula of Morphological Gradient −
Gradient = (AB) (AB)
where A is the input image and B is the structuring element.
Top-Hat Transform
The Top-Hat Transform is used to extract small bright or dark regions in an image. It comes in two variations as mentioned below −
- White Top-Hat: This extracts bright regions smaller than the structuring element.
- Black Top-Hat: It extracts dark regions smaller than the structuring element.
The White Top-Hat Transform is performed by subtracting the result of Opening from the original image, while the Black Top-Hat Transform is performed by subtracting the original image from the result of Closing. We have functions as white_tophat() and black_tophat() in scipy.ndimage module.
Following are the mathematical formulas of Top-Hat Transform −
White Top-Hat:
White Top-Hat = A (AB)
Black Top-Hat:
Black Top-Hat = (AB) A
where A is the input image and B is the structuring element.
Following are the functions available in scipy.ndimage module to perform the Morphological Operations in image processing −
S.No. | Function & Description |
---|---|
1 |
scipy.ndimage.binary_erosion() Perform erosion on a binary image (shrinking). |
2 |
scipy.ndimage.binary_dilation() Perform dilation on a binary image (expanding). |
3 |
scipy.ndimage.binary_opening() Perform binary opening i.e., erosion followed by dilation. |
4 |
scipy.ndimage.binary_closing() Perform binary closing i.e., dilation followed by erosion. |
5 |
scipy.ndimage.grey_erosion() Shrinks bright regions in the image. |
6 |
scipy.ndimage.grey_dilation() Expands bright regions in the image. |
7 |
scipy.ndimage.grey_opening() Perform grayscale opening, removing small bright spots. |
8 |
scipy.ndimage.grey_closing() Perform grayscale closing, filling small dark holes. |
9 |
scipy.ndimage.white_tophat_function() Enhances and extracts small bright features in images. |
10 |
scipy.ndimage.black_tophat_function() Enhances and extract small dark features from an image. |
Applications of morphological operations
Morphological operations are widely used in image processing and computer vision tasks. They provide effective tools for analyzing, pre-processing and enhancing image features by manipulating shapes and structures within images. Below are the key applications of morphological operations −
- Noise Removal: Removes small objects or artifacts using Opening i.e.,erosion followed by dilation.
- Image Preprocessing: Enhances images for segmentation and edge detection using Erosion and Dilation.
- Boundary Extraction: Extracts object boundaries by subtracting an eroded image from the original image.
- Object Detection and Segmentation: Identifies and isolates objects of interest using Closing and Opening.
- Skeletonization: Removes small objects or artifacts using Opening i.e.,erosion followed by dilation.
- Hole Filling: Fills small gaps or holes within objects using Closing.
- Edge Detection: Highlights object edges using Morphological Gradient (dilation - erosion).
- Shape Analysis: Analyzes and measures object properties like size, shape, and connectivity.
- Text Extraction: Extracts and enhances text regions in document images.