Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!
Blur Filters
Blur filters smooth out pixel variation in an image. Different blur types are suited for different tasks — from simple noise reduction to edge-preserving smoothing.
8 min•By Priygop Team•Updated 2026
Comparing Blur Filters
Comparing Blur Filters
import cv2
import numpy as np
image = cv2.imread("photo.jpg")
# Average Blur: simple mean of neighbourhood pixels
# Fast, but does not respect edges
avg = cv2.blur(image, (5, 5))
# Gaussian Blur: weighted average — centre pixels matter more
# Most commonly used. Good general-purpose pre-processing
gauss = cv2.GaussianBlur(image, (5, 5), sigmaX=0)
# Median Blur: replaces each pixel with the neighbourhood median
# Best for salt-and-pepper noise. Preserves edges well.
median = cv2.medianBlur(image, 5)
# Bilateral Filter: smooths while preserving sharp edges
# Use when you want smoothing without destroying contours
bilateral = cv2.bilateralFilter(image, d=9, sigmaColor=75, sigmaSpace=75)
# Box Filter: similar to average blur but more control
box = cv2.boxFilter(image, ddepth=-1, ksize=(5, 5))
# Print a comparison note
print("Blur comparison (all applied to same 5x5 neighbourhood):")
print(" Average: Fast, blurs everything uniformly")
print(" Gaussian: Weighted, more natural look")
print(" Median: Best for noise, preserves edges")
print(" Bilateral: Slowest, best edge preservation")
# Save for visual comparison
for name, result in [("avg", avg), ("gauss", gauss),
("median", median), ("bilateral", bilateral)]:
cv2.imwrite(f"blur_{name}.jpg", result)Diagram
Loading diagram…
Machine Learning follows a structured pipeline from data to deployment