
- MATLAB - Home
- MATLAB - Overview
- MATLAB - Features
- MATLAB - Environment Setup
- MATLAB - Editors
- MATLAB - Online
- MATLAB - Workspace
- MATLAB - Syntax
- MATLAB - Variables
- MATLAB - Commands
- MATLAB - Data Types
- MATLAB - Operators
- MATLAB - Dates and Time
- MATLAB - Numbers
- MATLAB - Random Numbers
- MATLAB - Strings and Characters
- MATLAB - Text Formatting
- MATLAB - Timetables
- MATLAB - M-Files
- MATLAB - Colon Notation
- MATLAB - Data Import
- MATLAB - Data Output
- MATLAB - Normalize Data
- MATLAB - Predefined Variables
- MATLAB - Decision Making
- MATLAB - Decisions
- MATLAB - If End Statement
- MATLAB - If Else Statement
- MATLAB - If…Elseif Else Statement
- MATLAB - Nest If Statememt
- MATLAB - Switch Statement
- MATLAB - Nested Switch
- MATLAB - Loops
- MATLAB - Loops
- MATLAB - For Loop
- MATLAB - While Loop
- MATLAB - Nested Loops
- MATLAB - Break Statement
- MATLAB - Continue Statement
- MATLAB - End Statement
- MATLAB - Arrays
- MATLAB - Arrays
- MATLAB - Vectors
- MATLAB - Transpose Operator
- MATLAB - Array Indexing
- MATLAB - Multi-Dimensional Array
- MATLAB - Compatible Arrays
- MATLAB - Categorical Arrays
- MATLAB - Cell Arrays
- MATLAB - Matrix
- MATLAB - Sparse Matrix
- MATLAB - Tables
- MATLAB - Structures
- MATLAB - Array Multiplication
- MATLAB - Array Division
- MATLAB - Array Functions
- MATLAB - Functions
- MATLAB - Functions
- MATLAB - Function Arguments
- MATLAB - Anonymous Functions
- MATLAB - Nested Functions
- MATLAB - Return Statement
- MATLAB - Void Function
- MATLAB - Local Functions
- MATLAB - Global Variables
- MATLAB - Function Handles
- MATLAB - Filter Function
- MATLAB - Factorial
- MATLAB - Private Functions
- MATLAB - Sub-functions
- MATLAB - Recursive Functions
- MATLAB - Function Precedence Order
- MATLAB - Map Function
- MATLAB - Mean Function
- MATLAB - End Function
- MATLAB - Error Handling
- MATLAB - Error Handling
- MATLAB - Try...Catch statement
- MATLAB - Debugging
- MATLAB - Plotting
- MATLAB - Plotting
- MATLAB - Plot Arrays
- MATLAB - Plot Vectors
- MATLAB - Bar Graph
- MATLAB - Histograms
- MATLAB - Graphics
- MATLAB - 2D Line Plot
- MATLAB - 3D Plots
- MATLAB - Formatting a Plot
- MATLAB - Logarithmic Axes Plots
- MATLAB - Plotting Error Bars
- MATLAB - Plot a 3D Contour
- MATLAB - Polar Plots
- MATLAB - Scatter Plots
- MATLAB - Plot Expression or Function
- MATLAB - Draw Rectangle
- MATLAB - Plot Spectrogram
- MATLAB - Plot Mesh Surface
- MATLAB - Plot Sine Wave
- MATLAB - Interpolation
- MATLAB - Interpolation
- MATLAB - Linear Interpolation
- MATLAB - 2D Array Interpolation
- MATLAB - 3D Array Interpolation
- MATLAB - Polynomials
- MATLAB - Polynomials
- MATLAB - Polynomial Addition
- MATLAB - Polynomial Multiplication
- MATLAB - Polynomial Division
- MATLAB - Derivatives of Polynomials
- MATLAB - Transformation
- MATLAB - Transforms
- MATLAB - Laplace Transform
- MATLAB - Laplacian Filter
- MATLAB - Laplacian of Gaussian Filter
- MATLAB - Inverse Fourier transform
- MATLAB - Fourier Transform
- MATLAB - Fast Fourier Transform
- MATLAB - 2-D Inverse Cosine Transform
- MATLAB - Add Legend to Axes
- MATLAB - Object Oriented
- MATLAB - Object Oriented Programming
- MATLAB - Classes and Object
- MATLAB - Functions Overloading
- MATLAB - Operator Overloading
- MATLAB - User-Defined Classes
- MATLAB - Copy Objects
- MATLAB - Algebra
- MATLAB - Linear Algebra
- MATLAB - Gauss Elimination
- MATLAB - Gauss-Jordan Elimination
- MATLAB - Reduced Row Echelon Form
- MATLAB - Eigenvalues and Eigenvectors
- MATLAB - Integration
- MATLAB - Integration
- MATLAB - Double Integral
- MATLAB - Trapezoidal Rule
- MATLAB - Simpson's Rule
- MATLAB - Miscellenous
- MATLAB - Calculus
- MATLAB - Differential
- MATLAB - Inverse of Matrix
- MATLAB - GNU Octave
- MATLAB - Simulink
MATLAB - Laplacian Filter
The Laplacian filter is a type of image enhancement filter used in image processing. It is used to sharpen images by emphasizing regions of rapid intensity change. The Laplacian filter is based on the Laplacian operator, which is a second-order derivative operator used to detect edges and fine details in images.
In the later part let us see different ways Laplacian filters can be used on images.
Laplacian Filter on Image using imfilter() in Matlab
In MATLAB, the Laplacian filter can be applied to an image using the imfilter function. The imfilter function convolves the image with a kernel that represents the Laplacian operator. This kernel highlights areas of rapid intensity change in the image, making edges appear sharper.
Syntax
output_image = imfilter(input_image, filter_kernel);
input_image − This is the input image to be filtered. It can be a grayscale image (2D array) or a color image (3D array with dimensions [height, width, channels]).
filter_kernel − This is the filter kernel or mask that defines how the filtering operation is performed. It is typically a 2D array (for 2D images) or a 3D array (for 3D images) that represents the weights of the filter. The size of the filter kernel determines the size of the neighborhood over which the filtering is applied. Common filter kernels include the Laplacian filter, Gaussian filter, Sobel filter, etc.
output_image − This is the output image after applying the filter. It has the same size and data type as the input image.
Let us see an example for Laplacian filter in imfilter() function
Example 1: Using Laplacian Filter in imfilter()
The code we have is −
% Read the image img = imread('peppers.png'); % Display the original image imshow(img); title('Original Image'); % Apply the Laplacian filter laplacian_filter = [0 -1 0; -1 4 -1; 0 -1 0]; filtered_img = imfilter(img, laplacian_filter); % Display the filtered image subplot(1, 2, 2); imshow(filtered_img, []); title('Laplacian Filtered Image');
In above example,
- The code uses the imread() function to read an image file named 'peppers.png' from the current directory. The image is stored in the variable img.
- The code uses the subplot function to create a figure with 1 row and 2 columns of subplots, and then selects the first subplot (1, 2, 1). The imshow() function is used to display the image img in this subplot. The title function sets the title of the subplot to 'Original Image'.
- The code defines a 3x3 Laplacian filter kernel laplacian_filter which is used to perform image filtering. The Laplacian filter is applied to the original image using the imfilter() function, and the result is stored in the variable filtered_img.
- Similar to displaying the original image, the code uses subplot to select the second subplot (1, 2, 2) and imshow() to display the filtered image filtered_img. The title of this subplot is set to 'Laplacian Filtered Image'.
The output we get is as follows −

Laplacian Filter on Image Using conv2() in Matlab
conv2() is a MATLAB function used for 2D convolution, which is a fundamental operation in image processing. It's commonly used for applying filters to images, such as blurring, sharpening, edge detection, and more.
Syntax
C = conv2(A, B, 'same');
In the syntax
- A is the input image or matrix.
- B is the 2D filter kernel (such as the Laplacian filter).
- 'same' is an optional parameter that specifies the size of the output matrix C to be the same as the input matrix A.
Let us see an example for same
Example
The code we have is -
% Read the image as grayscale img_gray = imread('peppers.jpg'); % Define the Laplacian filter kernel laplacian_filter = [0 -1 0; -1 4 -1; 0 -1 0]; % Apply the Laplacian filter using conv2 filtered_img = conv2(double(img_gray), laplacian_filter, 'same'); % Display the original and filtered images subplot(1, 2, 1); imshow(img_gray); title('Original Image'); subplot(1, 2, 2); imshow(uint8(filtered_img)); title('Laplacian Filtered Image');
In the example above,
- Reads the image 'peppers.jpg' as a grayscale image and stores it in the variable img_gray.
- Defines a 3x3 Laplacian filter kernel laplacian_filter. This kernel is used for edge detection.
- Laplacian Filter using conv2: Converts the grayscale image to a double precision matrix using double(img_gray).Applies the Laplacian filter to the grayscale image using conv2, which performs 2D convolution.The 'same' option ensures that the output image has the same size as the input image.
- To display original and filtered images : For this subplot is used to create a figure with two subplots.Displays the original grayscale image in the first subplot.Displays the Laplacian-filtered image in the second subplot after converting it back to uint8 format using uint8(filtered_img).
When we execute the code in matlab commad window the output we get is −
