Computer >> Computer tutorials >  >> Programming >> Python

Bilateral filtering using OpenCV


In this program, we will perform bilateral filtering in an image. Bilateral filter is used for smoothening images and reducing noise, while preserving edges. We will use the bilateralFilter() function for this purpose. This function takes in diameter of each pixel, value of sigma in color space and value of sigma in coordinate space.

Original Image

Bilateral filtering using OpenCV

Algorithm

Step 1: Import cv2.
Step 2: Read the image.
Step 3: Call the bilateralfilter() function.
Step 4: Display the output.

Example Code

import cv2

image = cv2.imread('testimage.jpg')
blur = cv2.bilateralFilter(image, 29,100,100)
cv2.imshow('BilateralFilter', blur)

Output

Bilateral filtering using OpenCV