OpenCV Gaussian Blurring for Images in Python

In this OpenCV article we are going to talk about Gaussian Blurring for Images in Python,

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

using Averaging, you can check that article in the below link.

 

 

 

Read More Image Smoothing techniques in OpenCV

1: OpenCV Averaging Image Blurring in Python

 

 

 

So in Gaussian Blurring method we need to specify width and height of the kernel which should be

positive and odd. also we need to add standard deviation in the x and y directions. sigmax

and sigmay. you can use cv2.GaussianBlur() for this in opencv

 

 

 

So now this is the complete code for OpenCV Gaussian Blurring for Images in Python

 

 

 

 

 

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

in your working directory.

 

 

 

 

So in here we are going to create our Gaussian Blur using cv2.GaussianBlur() function.

we need to give some parameters, our image, kernel size, sigmax and sigmay.

 

 

 

 

 

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.

 

 

 

 

 

 

So now run the complete code and this will be the result.

OpenCV Gaussian Blurring for Images in Python
OpenCV Gaussian Blurring for Images in Python

Subscribe and Get Free Video Courses & Articles in your Email

 

Comments are closed.

Codeloop
Share via
Copy link
Powered by Social Snap
×