Open In App

Python | Image blurring using OpenCV

Last Updated : 01 Aug, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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.

Python
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:

blur1
Original image
Python
Gaussian = cv2.GaussianBlur(resized_image, (15, 15), 0)  
Gaussian_rgb = cv2.cvtColor(Gaussian, cv2.COLOR_BGR2RGB)  
plt.imshow(Gaussian_rgb)
plt.title('Gaussian Blurred Image')
plt.axis('off')
plt.show()

Output:

blur2
Gaussian Blurring

2. Median Blur

Median blur is a non-linear filter which means it doesn't average the pixel values. Instead, it replaces each pixel with the median value of its neighboring pixels. This technique is useful for removing salt-and-pepper noise (random black and white pixels) while keeping the edges intact.

Python
median = cv2.medianBlur(resized_image, 11)  
median_rgb = cv2.cvtColor(median, cv2.COLOR_BGR2RGB)  

plt.imshow(median_rgb)
plt.title('Median Blurred Image')
plt.axis('off')
plt.show()

Output:

blur3
Median Blur

3. Bilateral Blur

The bilateral filter is a more advanced technique that smooths the image while preserving edges. It calculates a weighted average based on both the spatial distance and the pixel intensity. This means that it will blur areas with similar colors and preserve sharp edges, making it useful for noise reduction without sacrificing important details.

Python
bilateral = cv2.bilateralFilter(resized_image, 15, 150, 150)  
bilateral_rgb = cv2.cvtColor(bilateral, cv2.COLOR_BGR2RGB)  

plt.imshow(bilateral_rgb)
plt.title('Bilateral Blurred Image')
plt.axis('off')
plt.show()

Output:

blur4
Bilateral Blur

Challenges of Image Blurring

  1. Loss of Detail: While blurring can be useful, it may also blur important details in an image, reducing its overall clarity and making analysis difficult in certain contexts.
  2. Over-blurring: Overuse of blurring techniques can lead to overly soft or unrealistic images, losing sharpness and making it harder to identify key elements.
  3. Computational Cost: Advanced blurring methods such as bilateral filtering, may require significant computational resources, especially for large images or real-time applications.

Practice Tags :

Similar Reads