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!
Image Blurring
Blurring (smoothing) reduces noise and detail in an image. It is a critical pre-processing step before edge detection, thresholding, and other operations.
8 min•By Priygop Team•Updated 2026
Blur Methods
Blur Methods
import cv2
image = cv2.imread("photo.jpg")
# METHOD 1: Average blur — simple average of kernel pixels
# Fast but not great for edges. (kernel must be odd-sized)
avg_blur = cv2.blur(image, (5, 5))
# METHOD 2: Gaussian blur — weighted average, centre pixels count more
# Most commonly used. Great for pre-processing before edge detection.
gaussian = cv2.GaussianBlur(image, (5, 5), sigmaX=0)
# Larger kernel = more blur: (3,3) light, (15,15) heavy
# METHOD 3: Median blur — each pixel becomes the median of its neighbourhood
# Best for removing salt-and-pepper noise. Preserves edges better.
median = cv2.medianBlur(image, 5) # ksize must be odd
# METHOD 4: Bilateral filter — blurs but preserves edges
# Useful for noise removal while keeping important edges sharp
bilateral = cv2.bilateralFilter(image, d=9, sigmaColor=75, sigmaSpace=75)
# Slowest but best quality
cv2.imwrite("gaussian_blur.jpg", gaussian)
cv2.imwrite("median_blur.jpg", median)
cv2.imwrite("bilateral.jpg", bilateral)
print("Blur operations:")
print(" GaussianBlur: general pre-processing")
print(" medianBlur: salt-and-pepper noise")
print(" bilateralFilter: preserve edges while smoothing")Diagram
Loading diagram…
Machine Learning follows a structured pipeline from data to deployment