Median Blurring and Image Denoising
Have you ever taken a photo in low light and noticed it looked “grainy” or full of tiny colored speckles? That’s image noise. Noise comes from many sources—camera sensors in low light, scanning errors, or even compression artifacts. To make an image look clean without making it look “fake,” we need a filter that removes the random noise but keeps the edges and details. That’s where Median Blurring comes in.
How Median Blurring Works (In Simple Terms)
Imagine looking at a group of numbers and asking, “What’s the middle value here?” That’s the median. Median blurring applies the same idea to pixels. Instead of averaging all pixel values (which can blur edges too much), it picks the middle value in a neighborhood. This way, outliers (like very bright or very dark noisy pixels) are ignored, while the true structure of the image remains.
Example: Noise Reduction
Mathematical Explanation
Let’s define it more formally. Suppose we have a grayscale image represented as a 2D matrix I(x, y), where each value is the pixel intensity at location (x, y). For a kernel (window) size of k × k, we collect all pixel values in the window around (x, y):
where r = (k - 1) / 2. Then, the new pixel value is:
Unlike the mean (average), which can be skewed by extreme noise pixels, the median is robust — it picks the “middle” value, making it resistant to sudden spikes. That’s why median blur is excellent for removing salt-and-pepper noise.
Why Use Median Blur?
- Noise Reduction: Cleans up “salt-and-pepper” noise while preserving edges.
- Edge Preservation: Unlike Gaussian or mean filters, edges remain sharp.
- OCR Enhancement: Improves text recognition by cleaning scanned images.
- Photography: Enhances night or low-light photos without making them look plastic.
Kernel Size Matters
The size of the kernel determines how strong the denoising effect is:
- 3×3: Light smoothing, preserves most details.
- 5×5: Stronger smoothing, suitable for moderate noise.
- 7×7: Heavy smoothing, good for very noisy or scanned images.
Always use an odd number (3, 5, 7…) so there’s a clear center pixel.