
- 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 - Laplacian Filter
Laplacian Filter in SciPy
The Laplacian filter is a second-order derivative filter used to highlight regions of rapid intensity change in an image such as edges. It calculates the Laplacian which is the sum of the second derivatives in the x and y directions.
For a 2D image I(x,y), mathematically the Laplacian is given as follows −

This operation captures regions where the intensity changes abruptly. When we want to implement the Laplacian filter using scipy library then we can use the function scipy.ndimage.laplace().
Syntax
Following is the syntax of the scipy.ndimage.laplace() function −
scipy.ndimage.laplace(input, output=None, mode='reflect', cval=0.0)
Following are the parameters of the function scipy.ndimage.laplace() −
- input: The input array i.e., image to which the filter is applied.
- output(optional): An array to store the result. If not provided then a new array is created.
- mode: This parameter defines how the input array is extended at its boundaries. The modes can be 'reflect', 'constant', 'nearest', 'mirror' and 'wrap'.
- cval: This is a value to fill past edges if mode='constant'. Default value is 0.0.
Basic Laplacian Filter on a Synthetic Image
Following is an example which shows how to apply the basic Laplacian Filter on a synthetic image using the function scipy.ndimage.laplace() −
import numpy as np import matplotlib.pyplot as plt from scipy import ndimage # Create a synthetic checkerboard pattern x = np.indices((100, 100)).sum(axis=0) % 2 image = x.astype(float) # Apply the Laplacian filter laplacian = ndimage.laplace(image) # Plot plt.figure(figsize=(10, 5)) plt.subplot(1, 2, 1) plt.title("Checkerboard Pattern") plt.imshow(image, cmap='gray') plt.axis('off') plt.subplot(1, 2, 2) plt.title("Laplacian Filter") plt.imshow(laplacian, cmap='gray') plt.axis('off') plt.show()
Following is the output of the basic laplacian filter applied on the given image −

Laplacian Filter with Pre-Smoothing
The Laplacian filter with pre-smoothing is a technique in image processing where a Gaussian filter is applied to reduce noise before applying the Laplacian filter. This combination is effective for edge detection while minimizing noise artifacts. Following is the example applying a Gaussian filter before the Laplacian filter on a noisy image −
import numpy as np from scipy import ndimage import matplotlib.pyplot as plt # Create a noisy image np.random.seed(42) image = np.random.random((100, 100)) # Apply Gaussian smoothing before Laplacian filter smoothed = ndimage.gaussian_filter(image, sigma=2) laplacian = ndimage.laplace(smoothed) # Plot plt.figure(figsize=(15, 5)) plt.subplot(1, 3, 1) plt.title("Original Noisy Image") plt.imshow(image, cmap='gray') plt.axis('off') plt.subplot(1, 3, 2) plt.title("Smoothed Image") plt.imshow(smoothed, cmap='gray') plt.axis('off') plt.subplot(1, 3, 3) plt.title("Laplacian Filter (Post-Smoothing)") plt.imshow(laplacian, cmap='gray') plt.axis('off') plt.show()
Following is the output of the applying the Laplace Filter with Pre - smoothing −

Laplacian Filter with Boundary Modes
In the Laplacian filter and Gaussian smoothing the boundary modes control how the edges of the image are handled during the convolution. This is important because the filter operates beyond the original image's boundaries. Here in this example we are passing the mode parameter to the scipy.ndimage.laplace() function −
import numpy as np import matplotlib.pyplot as plt from scipy import ndimage from skimage import data, color # Step 1: Load image image = color.rgb2gray(data.astronaut()) # Convert to grayscale # Step 2: Pre-smoothing with Gaussian filter sigma = 2 smoothed_image = ndimage.gaussian_filter(image, sigma=sigma) # Step 3: Apply Laplacian filter with different modes modes = ['reflect', 'constant', 'nearest', 'mirror', 'wrap'] results = {} for mode in modes: laplacian = ndimage.laplace(smoothed_image, mode=mode, cval=0) # cval=0 for 'constant' results[mode] = laplacian # Step 4: Visualize the results plt.figure(figsize=(15, 10)) plt.subplot(2, 3, 1) plt.title("Original Image") plt.imshow(image, cmap='gray') plt.axis('off') for i, mode in enumerate(modes, start=2): plt.subplot(2, 3, i) plt.title(f"Mode: {mode}") plt.imshow(results[mode], cmap='gray') plt.axis('off') plt.tight_layout() plt.show()
Following is the output of the applying the Laplace Filter with Pre - smoothing −
