0
0
Computer Visionml~20 mins

Blurring and smoothing (Gaussian, median, bilateral) in Computer Vision - ML Experiment: Train & Evaluate

Choose your learning style9 modes available
Experiment - Blurring and smoothing (Gaussian, median, bilateral)
Problem:You want to reduce noise in images using blurring techniques. Currently, you apply Gaussian blur but notice that edges become too soft and important details are lost.
Current Metrics:Visual quality: Noise reduced but edges are blurry and details lost.
Issue:The Gaussian blur smooths the entire image uniformly, causing loss of sharp edges and details.
Your Task
Improve image smoothing to reduce noise while preserving edges better than Gaussian blur alone.
Use only Gaussian, median, and bilateral blurring methods.
Do not use any deep learning or complex denoising algorithms.
Process the same input image for fair comparison.
Hint 1
Hint 2
Hint 3
Solution
Computer Vision
import cv2
import numpy as np
from matplotlib import pyplot as plt

# Load noisy image
image = cv2.imread('noisy_image.jpg')
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Apply Gaussian blur
gaussian = cv2.GaussianBlur(image_rgb, (7,7), 1.5)

# Apply Median blur
median = cv2.medianBlur(image_rgb, 7)

# Apply Bilateral filter
bilateral = cv2.bilateralFilter(image_rgb, d=9, sigmaColor=75, sigmaSpace=75)

# Plot results
plt.figure(figsize=(12,8))
plt.subplot(2,2,1)
plt.title('Original')
plt.imshow(image_rgb)
plt.axis('off')

plt.subplot(2,2,2)
plt.title('Gaussian Blur')
plt.imshow(gaussian)
plt.axis('off')

plt.subplot(2,2,3)
plt.title('Median Blur')
plt.imshow(median)
plt.axis('off')

plt.subplot(2,2,4)
plt.title('Bilateral Filter')
plt.imshow(bilateral)
plt.axis('off')

plt.tight_layout()
plt.show()
Added median blur which replaces each pixel with the median of neighboring pixels, preserving edges better than Gaussian.
Added bilateral filter which smooths flat regions but keeps edges sharp by considering pixel intensity differences.
Compared all three methods visually on the same noisy image.
Results Interpretation

Before: Gaussian blur reduces noise but blurs edges and details.

After: Median blur removes noise and preserves edges better. Bilateral filter smooths noise while keeping edges sharpest among the three.

Different blurring methods affect images differently. Median and bilateral filters are better for noise removal when edge preservation is important.
Bonus Experiment
Try combining bilateral filter with a small Gaussian blur to see if noise can be reduced further without losing edges.
💡 Hint
Apply bilateral filter first, then a light Gaussian blur, and compare results visually.