Skip to content
Related Articles
Open in App
Not now

Related Articles

Laplacian Filter using Matlab

Improve Article
Save Article
  • Difficulty Level : Expert
  • Last Updated : 06 Dec, 2022
Improve Article
Save Article

Laplacian filter is a second-order derivative filter used in edge detection, in digital image processing. In 1st order derivative filters, we detect the edge along with horizontal and vertical directions separately and then combine both. But using the Laplacian filter we detect the edges in the whole image at once.

The Laplacian Operator/Filter is = [0 1 0; 
                                    1 -4 1;
                                    0 1 0]
here the central value of filter is negative.
Filter is = [0 -1 0;
            -1 4 -1; 
             0 -1 0],
here the central value of filter is positive.
Note:The sum of all values of the filter is always 0.


  • Read the image in Matlab, using imread() function.
  • If the image is colored then convert it into RGB format.
  • Define the Laplacian filter.
  • Convolve the image with the filter.
  • Display the binary edge-detected image.


  var_name = imread(” name of image . extension “); //Read the image in variable

ar_name = rgb2gray ( old_image_var); //Convert into grayscale

 “conv2( )” //Convolution is performed 

“imtool( )” is used for displaying image.



% MATLAB code for
% Edge detection using Laplacian Filter.
% Convert rgb image to grayscale.
% Convert into double format.
% Define the Laplacian filter.
Laplacian=[0 1 0; 1 -4 1; 0 1 0];
% Convolve the image using Laplacian Filter
k2=conv2(k1, Laplacian, 'same');
% Display the image.
imtool(k1, []);






Figure: Input Image



Figure: Output image after Edge detection




  • We should note that first derivative operators exaggerate the effects of noise. Second derivatives will exaggerate noise twice as much.
  • No directional information about the edge is given.




My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!