
- 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 - Low Pass Filters
SciPy - Low Pass Filters
Low-pass filters are also called as Smoothing filters which are used in image processing to smooth or blur an image by reducing high-frequency components such as noise or rapid intensity changes. These filters preserve low-frequency information i.e., smooth variations while attenuating high-frequency details like edges or noise.
Mathematically we can give a low-pass filter which modifies the image I(x,y) by convolving it with a kernel K as follows −

Following are the different types of Low pass filters available in scipy −
Box Filter in SciPy
A Box filter is also called as Uniform filter which computes the average intensity of all pixels in a neighborhood defined by a kernel size. It is simple and fast but may blur edges. In scipy we have the function scipy.ndimage.uniform_filter() to apply the box filter to an image. The size parameter defines the neighborhood size and large sizes result in more blur but reduce image details.
Following is an example which applies the uniform filter on an image with the help of the function scipy.ndimage.uniform_filter() −
from scipy.ndimage import uniform_filter import matplotlib.pyplot as plt from skimage import data # Load an example image image = data.camera() # Apply a box filter (uniform filter) with a size of 5x5 filtered_image = uniform_filter(image, size=5) # Display original and filtered images plt.figure(figsize=(12, 6)) plt.subplot(1, 2, 1) plt.title("Original Image") plt.imshow(image, cmap="gray") plt.subplot(1, 2, 2) plt.title("Box Filter (5x5)") plt.imshow(filtered_image, cmap="gray") plt.show()
Below is the output of the box filter −

Gaussian Filter in SciPy
The Gaussian filter is one of the most popular low-pass filters. It uses a Gaussian kernel where pixels closer to the center of the kernel have higher weights. We have the function scipy.ndimage.guassian_filter() to use the Gaussian filter on an image.
The Gaussian kernel is defined as follows −

Where, is the Standard deviation of the Gaussian which controls the amount of smoothing.
is used to control the degree of smoothing where larger values result in greater blur and Gaussian smoothing is ideal for removing noise without severely blurring edges.
Below is an example which shows how to use the gaussian filter on an image with the help of the function scipy.ndimage.guassian_filter() −
from scipy.ndimage import gaussian_filter import matplotlib.pyplot as plt from skimage import data # Load an example image image = data.camera() # Apply Gaussian filter with standard deviation sigma=2 gaussian_blurred = gaussian_filter(image, sigma=2) # Display original and blurred images plt.figure(figsize=(12, 6)) plt.subplot(1, 2, 1) plt.title("Original Image") plt.imshow(image, cmap="gray") plt.subplot(1, 2, 2) plt.title("Gaussian Filter (sigma=2)") plt.imshow(gaussian_blurred, cmap="gray") plt.show()
Here is the output of the Gaussian filter −

Mean Filter in SciPy
The mean filter replaces each pixel with the average of its neighbors. While effective for noise reduction it does not preserve edges well.
The kernel averages the pixel intensities which lead to a simple smoothing effect and larger kernels increase the smoothing effect but at the cost of edge detail.
In this example we are applying the mean filter to the given input image by using the function scipy.ndimage.convolve() −
from scipy.ndimage import convolve import numpy as np import matplotlib.pyplot as plt from skimage import data # Load an example image image = data.camera() # Define a mean filter kernel (3x3) mean_kernel = np.ones((3, 3)) / 9 # Apply mean filter using convolution mean_filtered = convolve(image, mean_kernel) # Display original and mean-filtered images plt.figure(figsize=(12, 6)) plt.subplot(1, 2, 1) plt.title("Original Image") plt.imshow(image, cmap="gray") plt.subplot(1, 2, 2) plt.title("Mean Filter (3x3)") plt.imshow(mean_filtered, cmap="gray") plt.show()
Following is the output of the Mean filter −

Here is an example which compares all the three different types of Low pass filters that we can use on the given input image −
from scipy import ndimage import numpy as np import matplotlib.pyplot as plt from skimage import data # Load an example image image = data.camera() # Define a mean filter kernel (3x3) mean_kernel = np.ones((3, 3)) / 9 # Apply different filters and compare gaussian = ndimage.gaussian_filter(image, sigma=2) mean = ndimage.convolve(image, mean_kernel) box = ndimage.uniform_filter(image, size=5) # Display results plt.figure(figsize=(15, 8)) plt.subplot(2, 2, 1) plt.title("Original Image") plt.imshow(image, cmap="gray") plt.subplot(2, 2, 2) plt.title("Gaussian Filter") plt.imshow(gaussian, cmap="gray") plt.subplot(2, 2, 3) plt.title("Mean Filter") plt.imshow(mean, cmap="gray") plt.subplot(2, 2, 4) plt.title("Box Filter") plt.imshow(box, cmap="gray") plt.tight_layout() plt.show()
Following is the output of the above code for comparing the different low pass filters −
