This project demonstrates different image denoising techniques using OpenCV in Python. Image noise is a common problem caused by factors like low light, camera quality, or transmission errors. Here, we compare three popular filters — Gaussian Blur, Median Blur, and Bilateral Filter — to see how each one improves image quality while preserving important details.
✅ Removes noise from images using multiple filters
✅ Compares results visually in a single window
✅ Preserves edges and colors effectively (especially with Bilateral Filter)
✅ Easy-to-understand and beginner-friendly code
- Gaussian Blur – Smooths the image by averaging neighboring pixels (good for general noise).
- Median Blur – Works best for “salt and pepper” noise by replacing each pixel with the median of its neighbors.
- Bilateral Filter – Reduces noise while keeping edges sharp; ideal for natural photos.
pip install opencv-python numpy matplotlib- OpenCV – for image processing
- NumPy – for numerical operations
- Matplotlib – for visualization
python
import cv2
import numpy as np
import matplotlib.pyplot as plt
def denoise_image(image_path):
noisy_image = cv2.imread(image_path)
noisy_image_rgb = cv2.cvtColor(noisy_image, cv2.COLOR_BGR2RGB)
gaussian = cv2.GaussianBlur(noisy_image, (5,5), 0)
median = cv2.medianBlur(noisy_image, 5)
bilateral = cv2.bilateralFilter(noisy_image, 9, 75, 75)
plt.figure(figsize=(15,10))
plt.subplot(2,2,1); plt.title('Noisy Image'); plt.imshow(noisy_image_rgb); plt.axis('off')
plt.subplot(2,2,2); plt.title('Gaussian Blur'); plt.imshow(cv2.cvtColor(gaussian, cv2.COLOR_BGR2RGB)); plt.axis('off')
plt.subplot(2,2,3); plt.title('Median Blur'); plt.imshow(cv2.cvtColor(median, cv2.COLOR_BGR2RGB)); plt.axis('off')
plt.subplot(2,2,4); plt.title('Bilateral Filter'); plt.imshow(cv2.cvtColor(bilateral, cv2.COLOR_BGR2RGB)); plt.axis('off')
plt.show()
denoise_image('sample_image.jpg')The program displays a 2×2 grid: | Noisy Image | Gaussian Blur | Median Blur | Bilateral Filter |
- Gaussian Blur: Smooths noise but slightly blurs edges.
- Median Blur: Excellent for salt-and-pepper noise.
- Bilateral Filter: Keeps edges sharp and natural.