Instagram
youtube
Facebook
Twitter

Bilateral Filter

The bilateral filter is a tool used to clean up an image by removing small, unwanted details while keeping the important parts of the image, like edges. It works by looking at the pixels around a specific pixel and averaging their color values. But it doesn't treat all pixels the same way, it gives more importance to the pixels that are similar in color and closer to the center pixel. This tool  helps to make the image look cleaner and more smooth, while also keeping important features like edges visible. In this tutorial, we’ll learn about OpenCV bilateral filters with some practical work.

Let's understand the concept with some practical work.

Example:

Input

Code:

import cv2
img = cv2.imread('demo.png')  
image = cv2.bilateralFilter(img, 15,95,75)
cv2.imshow('Bilateral filtered Image', image)
cv2.waitKey(0)  
cv2.destroyAllWindows()

Here, first, we imported cv2 and used cv2.imread to read the image. Then, we used cv2.bilateralFilter to apply a bilateral filter on the input image. We passed some parameters to declare the diameter of the pixel area used during filtering (15), the standard deviation in the intensity of the pixels (95), and the standard deviation in the spatial domain (75). At last, we used cv2.imshow function to display the filtered image.

Result:

We can also use some blur techniques like - gaussian blur with a bilateral filter to enhance the quality of the result.