What is the Laplacian filter?

In digital image processing, we use a Laplacian filter to compute the second-order derivative of an image to detect edges. We need a Laplacian filter so that we can extract the features of the image in a better way. The better we can extract the features of the image, the better we will make the model to train.

Why do we use the Laplacian filter?

The question arises of why we need to compute the second-order derivative when the first-order derivative is doing the work. We detect the horizontal and vertical edges in first-order derivatives and combine them. On the other hand, the second-order derivative allows us to detect all the edges of an image at once. Have a look at the Laplacian filters given below.

Laplacian filter
Laplacian filter

Mathematical background

As we have discussed earlier, in the Laplacian filter, we are interested in finding the second-order derivatives of the image vertically and horizontally. So the equation of this scenario is given below.

In this equation,

  • XX is the columns index of the pixel.

  • YY is the row index of the pixel.

  • F(X,Y)F(X,Y) represents the intensity of the image at pixel XX and YY.

  • \nablarepresents the gradient.

This equation represents how we take second-order derivation of an image.

Code

The code for applying convolution with Laplacian is given below. As you know, Image is represented in the form of an array.

import numpy as np
def WindowMultiply(LaplacianFilter,Image,row,col):
Result=0
for i in range(3):
for c in range(3):
Result=Result+LaplacianFilter[i][c]*Image[i+row][col+c]
return Result
def ConvolutionWithLaplacian(fitler,Image):
Result = np.random.rand(3,4)
for i in range(3):
for c in range(4):
Result[i][c]=WindowMultiply(LaplacianFilter,Image,i,c)
return Result
if __name__=="__main__":
LaplacianFilter=np.array([[0,-1,0],
[-1,4,-1],
[0,-1,0]])
Image=np.array([[4,7,10,1,14,5],[8,13,8,10,18,20],[7,8,54,10,3,10],[9,6,9,7,9,12],[54,9,1,9,5,9]])
Result=ConvolutionWithLaplacian(LaplacianFilter, Image)
print("Result after Convolution with Laplacian Filter : ")
print(Result)

The explanation of the code is given below.

  • Line 3–8: The function WindowMultiply() multiplies the LaplacianFilter and window of the Image.

  • Line 10–15: ConvolutionWithLaplacian() performs the convolution of the image with a filter. The nested for loops in this function indicates the sliding window, and for each sliding window, we call the function WindowMultiply().

  • Line 21–23: Initializing the Laplacian filter.

  • Line 24: Represents the Image in the form of an array.

  • Line 25: Storing the convolution result in the variable Result.

Note: If you are curious to learn about how the convolution is done then please refer to this link.

Example

Look at the picture to which we have applied the Laplacian filter. Observe how the Laplacian filter helps us detect all the edges of an image.

Applying Laplacian filter
Applying Laplacian filter

Applications of Laplacian filter

We use the Laplacian filter in various tasks. Besides detecting edges, many other wide-range applications of Laplacian filters, some of which are illustrated below.

Applications of Laplacian filter
Applications of Laplacian filter

Conclusion

Laplacian filters help in convolutional neural networks. These networks are designed to deal with images. So with the help of convolution, we extract the features of the image. Feature extraction is defined by the type of filter we are using. Edge-detecting filters detect the edges present in the images.
Similarly, the Laplacian filter is also used to find the overall edges. It computes the rate of change of the first derivative. So it is very sensitive in detecting the edges of the image.

Q

What is the primary purpose of the Laplacian filter in image processing?

A)

Color correction

B)

Noise addition

C)

Edge detection

D)

Blur reduction

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved