Smoothing Images using OpenCV

Aishwarya Valse
3 min readApr 11, 2021

Today I am back with a new article. I am writing this article because I had started with this topic to learn when I was new to OpenCV. In this article, I am trying to explain the noise removal techniques. I hope you will enjoy reading it.

You will learn the below topics in this article:

  1. Custom-made filter to images
  2. Image Blurring
  • Averaging
  • Gaussian Filtering
  • Median Filtering

2D Convolutional:

What is Convolutional in Image Processing?

It is a simple mathematical operation between two arrays of numbers, different sizes, but the same dimensionality to produce the third. The convolution happens between kernel and array. Kernal is another array that is smaller than the original image. Images can be filtered with a low pass and high pass filter. A low pass filter will help in removing noise and a high pass will find the edges in the image. OpenCV provides a function cv.filter2D() to filter the image.

Low Pass Filter

The above code is for a low pass filter. We can see the noise has removed from the image.

The below code is for the high-pass filter. Here you can see, this filter is detecting the edges.

High Pass Filter

Image filtering can achieve by some other techniques as well.

Image Blurring

  1. Averaging:

Image can have various types of noises which reduces the quality of the image. Blurring can help us to remove the noise and improve the quality of the image. In the average technique, the central element of the image is replaced by the average of all the pixels in the kernel area.

The blurring of the image depends on the kernel size. If the kernel size is too small then it is not able to remove noise from the image.

OpenCV provides cv2.blur() function which is quick for filtering and performing averaging.

Averaging

Here we can see the difference between both images. The second image is quite a blur than the first.

2. Gaussian Blurring:

In gaussian blurring, a Gaussian kernel is used instead of a box filter.

1D gaussian kernel will look like this. OpenCV provides cv2.GaussianBlur() function.

Gaussian Blur

3. Median Blurring:

In median blurring, it takes median of all pixels under the kernel area and replace central value with median.

Median Blur

Now, you can see differences between all the filters.

This is all about the filters in OpenCV. Here I have covered some basics of image processing to with the OpenCV. In the next article, I will come with new topic of OpenCV.

Thank you for reading.

Happy Learning!!! :)

--

--

Aishwarya Valse

🚀 Data Science & ML Enthusiast 📊 | Blogger 🖋️ | Lifelong Learner 🌱 | Inspiring growth in tech & personal development 💡✨ | Let's code, learn, and thrive tog