Monday, 11 December 2023

What is Image Bilateral Blurring and how to use it?

 

Bilateral blurring blur or smooth the image while preserving edges and important details. Unlike median, average and Gaussian filters, it is a non-linear filter.

 

How to apply Bilateral blurring on an image?

Using cv2.bilateralFilter method, we can apply bilateral blurring on an image.

 

Signautre

dst = cv2.bilateralFilter(src, d, sigma_color, sigma_space[, dst[, borderType]])

 

Following table summarizes the parameters of bilateralFilter method.

 

Parameter

Description

src

This is the source image, where you want to apply bilateral filtering.

d

Specifies the diameter of each pixel neighborhood. It is used to control the size of neighborhood used for filtering.

 

If ‘d’ is smaller, then smaller neighbourhood is used, if ‘d’ is larger, then a wider neighbourhood is used.

sigma_color

It controls the color similarity between neighboring pixels.

sigma_space

It is used to control the spatial proximity of neighboring pixels.  A larger sigma_space value means that pixels farther away from the central pixel will have a higher influence on the filtering.

dst

It is optional parameter.  If you provide this, then the output image stored in this variable.

borderType

It is optional parameter, specifies the pixel extrapolation method for borders. By default, it uses BORDER_DEFAULT.

 

bilateral_filtering.py

import cv2 as cv

image = cv.imread('gateway_of_india.png')
cv.imshow('Original image', image)

blurred_image = cv.bilateralFilter(image, 15, 25, 35)
cv.imshow('Bilateral filter', blurred_image)

cv.waitKey(0)

# Close the OpenCV windows
cv.destroyAllWindows()

Output

Original image


 


Bilateral image



 

Previous                                                    Next                                                    Home

No comments:

Post a Comment