Image blurring is a technique used in image processing to reduce sharpness and detail making an image appear smoother. This is done by applying filters also called low-pass filters that reduce high-frequency noise and smooth finer details. Blurring is used for tasks like noise reduction, edge smoothing or creating artistic effects.
It works by averaging the pixel values around each pixel, softening the image in the process. It’s useful in scenarios where minimizing noise or reducing sharpness is necessary such as in preparing images for computer vision models or applying a soft, artistic effect. In this article we will see how to do blurring using OpenCV.
Types of Blurring
We can apply various blurring techniques based on the desired effect.
1. Gaussian Blurring
Gaussian blur works by applying a Gaussian function to an image, resulting in a smooth blur. It’s useful for noise reduction and detail reduction in images. It is used as a preprocessing step for machine learning and deep learning models.
This kernel helps in averaging the nearby pixel values with closer pixels having a higher weight, creating a natural-looking blur.
Now first see the original image and then one by one we will apply different blurring methods on that image. Here we will be using Matplotlib and OpenCV for the implementation.
import cv2
from matplotlib import pyplot as plt
image_path = '/content/cats_dogs.jpg'
image = cv2.imread(image_path)
resized_image = cv2.resize(image, (1900, 800))
resized_image_rgb = cv2.cvtColor(resized_image, cv2.COLOR_BGR2RGB)
plt.imshow(resized_image_rgb)
plt.title('Original Image')
plt.axis('off')
plt.show()
Output: