
- 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 - ndimage.grey_dilation() Function
The scipy.ndimage.grey_dilation() is a function used to perform grayscale dilation on an image. Dilation in the view of Image Processing refers to expanding the boundaries of bright regions in a grayscale image by making them larger.
This function works by applying a structuring element over the image and for each pixel by replacing it with the maximum value of the pixels in the neighborhood defined by the structuring element. The result is an image where bright regions grow and dark regions shrink.
It is commonly used in image processing for noise removal by enhancing features or isolating specific structures in an image.
Syntax
Following is the syntax of the function scipy.ndimage.grey_dilation() to perform grey scale dilation on an image −
scipy.ndimage.grey_dilation(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)
Parameters
Following are the parameters of the scipy.ndimage.grey_dilation() function −
- input: The input image or array on which the grayscale dilation operation is applied. It can be a binary or grayscale image.
- size (optional): The size of the structuring element used for the dilation operation and specified as a tuple (e.g., (3, 3)). This defines the neighborhood dimensions.
- footprint (optional): A binary array that defines the shape of the structuring element. It overrides the size parameter when provided.
- structure (optional): An array specifying the weights for the structuring element. It overrides both size and footprint if provided.
- output (optional): The array where the result of the operation is stored. If not specified then a new array is created.
- mode (optional): This parameter defines how the boundaries of the image are handled. Available modes include 'reflect', 'constant', 'nearest', 'mirror' and 'wrap'. The default value is 'reflect'.
- cval (optional): The constant value used for padding when mode='constant'. The default value is 0.0.
- origin (optional): It controls the placement of the structuring element relative to the current pixel. A value of 0 centers the element, and positive or negative values shift it.
Return Value
The scipy.ndimage.grey_dilation() function returns an array of the same shape as the input where each pixel's value is replaced by the maximum value in the neighborhood defined by the structuring element.
Example of Basic Grayscale Dilation
Following is the example of the function scipy.ndimage.grey_dilation() in which grey scale Dilation operation is applied on a simple 2D array using a default 3x3 structuring element −
import numpy as np import scipy.ndimage as ndimage import matplotlib.pyplot as plt # Create a sample 2D grayscale image image = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # Apply grey dilation with default 3x3 size dilated_image = ndimage.grey_dilation(image, size=(3, 3)) # Display the original and dilated images plt.figure(figsize=(8, 4)) plt.subplot(1, 2, 1) plt.title("Original Image") plt.imshow(image, cmap='gray') plt.axis('off') plt.subplot(1, 2, 2) plt.title("Grey Dilation") plt.imshow(dilated_image, cmap='gray') plt.axis('off') plt.tight_layout() plt.show()
Following is the output of the function scipy.ndimage.grey_dilation() which is used to implement basic Example of Greyscale Dilation −

Grayscale Dilation with Larger Structuring
A larger structuring element will dilate the image more by considering a broader neighborhood of pixels for the operation. To perform grey dilation with a larger structuring element we can specify size parameter as larger for the grey_dilation() function. Here's an example that shows how the grey dilation with a larger structuring element works −
import numpy as np import scipy.ndimage as ndimage import matplotlib.pyplot as plt # Create a sample 2D grayscale image image = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # Apply grey dilation with a 5x5 structuring element dilated_image = ndimage.grey_dilation(image, size=(5, 5)) # Display the original and dilated images plt.figure(figsize=(8, 4)) plt.subplot(1, 2, 1) plt.title("Original Image") plt.imshow(image, cmap='gray') plt.axis('off') plt.subplot(1, 2, 2) plt.title("Grey Dilation (5x5 Structuring Element)") plt.imshow(dilated_image, cmap='gray') plt.axis('off') plt.tight_layout() plt.show()
Here is the output of the function scipy.ndimage.grey_dilation() which implement Greyscale Dilation with larger structuring element−

Grayscale Dilation with Different Origin
In the view of grey dilation the origin parameter specifies the position of the structuring element relative to the current pixel. By default the origin is at the center of the structuring element i.e., origin=0. However by changing the origin shifts the structuring element which can affect how dilation is applied to the image. Here's an example that shows how to perform grey dilation with different origins is applied to an image −
import numpy as np import scipy.ndimage as ndimage import matplotlib.pyplot as plt # Create a sample 2D grayscale image image = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # Apply grey dilation with a 3x3 structuring element and origin=1 dilated_image_origin_1 = ndimage.grey_dilation(image, size=(3, 3), origin=1) # Apply grey dilation with a 3x3 structuring element and origin=-1 dilated_image_origin_minus_1 = ndimage.grey_dilation(image, size=(3, 3), origin=-1) # Display the original and dilated images plt.figure(figsize=(12, 6)) # Original image plt.subplot(1, 3, 1) plt.title("Original Image") plt.imshow(image, cmap='gray') plt.axis('off') # Dilation with origin=1 plt.subplot(1, 3, 2) plt.title("Grey Dilation (origin=1)") plt.imshow(dilated_image_origin_1, cmap='gray') plt.axis('off') # Dilation with origin=-1 plt.subplot(1, 3, 3) plt.title("Grey Dilation (origin=-1)") plt.imshow(dilated_image_origin_minus_1, cmap='gray') plt.axis('off') plt.tight_layout() plt.show()
Below is the output of the function scipy.ndimage.grey_dilation() which implement Greyscale Dilation with different origin −
