OpenCV Averaging Image Blurring in Python

In this OpenCV article we are going to talk about Averaging Image Blurring in Python OpenCV.

so  according to OpenCV Documentation Averaging is done by convolving an image with a

normalized box filter. It simply takes the average of all the pixels under the kernel area and

replaces the central element. you can do this by using cv2.blur() function.

 

 

 

Read More Image Smoothing Techniques in OpenCV

1: OpenCV Gaussian Blurring for Images in Python

2: OpenCV Median Blurring for Images in Python

3: OpenCV Smooth Image with Bilateral Filtering

 

 

 

 

 

So this is the complete code for OpenCV Averaging Image Blurring 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 after that we are going to use cv2.blur() function for making smooth our image. we need

to give some parameters for this function, so the first one is our source or image that we want

to do blurring and the second is the ksize or kernel size, you can change this according to your

choice.

 

 

 

 

 

Because we are going to show our images 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.

 

 

 

 

Note: cv2.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 run the complete code and this will be the result.

OpenCV Averaging Image Blurring in Python
OpenCV Averaging Image Blurring in Python

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Comments are closed.

Share via
Copy link
Powered by Social Snap
×