OpenCV Smooth Image with Bilateral Filtering

In this OpenCV article we are going to learn about OpenCV Smooth Image with Bilateral Filtering.

so this is the fourth technique for image smoothing or blurring in OpenCV . the first one was

using Averaging, the second was using Gaussian Blurring and the third one was using Median

Blurring you can check the articles in the below links.

 

 

 

 

Read More Image Smoothing Techniques in OpenCV

1: OpenCV Averaging Image Blurring in Python

2: OpenCV Gaussian Blurring for Images in Python

3: OpenCV Median Blurring for Images in Python

 

 

 

A bilateral filter is non-linear, edge-preserving and noise-reducing smoothing filter. The

intensity value at each pixel in an image is replaced by a weighted average of intensity values

from nearby pixels. This weight can be based on a Gaussian distribution.

 

 

 

 

So now this is the complete code for OpenCV Smooth Image with Bilateral Filtering

 

 

 

 

 

OK for this purpose we are going to use this image, and we want to smooth this image

using Bilateral method.

Face Image
Face Image

 

 

 

 

This is the syntax for Bilateral Filtering.

 

dst It is the destination or output image
d A variable of the type integer representing the diameter of the pixel neighborhood.
sigmacolor A variable of the type integer representing the filter sigma in the color space.
sigmaspace A variable of the type integer representing the
filter sigma in the coordinate space.

 Also you can use borderType if you want.

 

 

 

 

This  line of code is used for reading of the image, make sure that you have added an image

in your working directory.

 

 

 

 

And in here we are going to create our Bilateral Filtering.

 

 

 

 

 

Because we are going to show our image in Matplotlib, so Matplotlib uses RGB (Red, Green, Blue)

color system, and OpenCV uses BGR (Blue, Green, Red) color system, we need to convert the BGR

color to RGB. if we don’t do this there will be messed up in the color.

 

 

 

 

 

Notecv2.waitKey() is a keyboard binding function. Its argument is the time in milliseconds.

the function waits  specified milliseconds for any keyboard event. If you press any key in that

time, the program continues. If 0 is passed, it waits indefinitely for a key stroke.

 

 

 

 

 

 

 

Run the complete code and this is the result.

OpenCV Smooth Image with Bilateral Filtering
OpenCV Smooth Image with Bilateral Filtering

Subscribe and Get Free Video Courses & Articles in your Email

 

Codeloop
Share via
Copy link
Powered by Social Snap
×