Smoothing & Blurring Filters
Smoothing (blurring) reduces noise and detail in an image by averaging or modifying pixel values based on their neighbors. It works as a low-pass filter, allowing low-frequency components (smooth regions) to pass while suppressing high-frequency components (noise, edges, fine details). They are almost always the first preprocessing step before edge detection or segmentation.
Classification of Smoothing Filters
graph TD
A[Smoothing Filters] --> B[Linear Filters]
A --> C[Non-Linear Filters]
B --> B1[Mean / Average Filter]
B --> B2[Gaussian Filter]
C --> C1[Median Filter]
C --> C2[Bilateral Filter]
C --> C3[Min/Max Filter]
style A fill:#4A90D9,color:#fff
style B fill:#7BB661,color:#fff
style C fill:#E8A04C,color:#fff1. Mean (Average) Filter
Linear Spatial
Replaces each pixel with the simple arithmetic average of all pixels in a rectangular neighborhood (kernel). Every neighbor contributes equally.
When to use ?
- Very simple to understand easy to implement method for smoothing images.
- Quick, low-cost noise reduction before further processing.
- When image quality is not critical and speed matters.
- Preprocessing step in simple pipelines.
When to avoid?
- When edges and fine details must be preserved — this filter blurs everything uniformly, including edges.
- On images with salt-and-pepper (impulse) noise — averaging will spread the outlier values rather than remove them.
The Mean Filter is the bluntest tool in the kit. It treats noise and edge information identically. Use it only when you need fast, rough smoothing and do not care about edge sharpness.
2. Gaussian Filter
Linear Spatial
The effect of Gaussian smoothing is to blur an image, in a similar fashion to the mean filter. The degree of smoothing is determined by the standard deviation of the Gaussian.
The Gaussian outputs a weighted average of each pixel's neighborhood, with the average weighted more towards the value of the central pixels. This is in contrast to the mean filter's uniformly weighted average. Because of this, a Gaussian provides gentler smoothing and preserves edges better than a similarly sized mean filter.
How it works?
Applies a weighted average using a Gaussian (bell-curve) function. Pixels closer to the center receive a higher weight than those at the edges of the kernel. The standard deviation
A common example of 3×3 discrete approximation (
The 2D Gaussian Formula
where
: The spatial distances from the center of the filter mask in the horizontal and vertical directions, respectively. : The spread of the filter. (standard deviation) : The variance. : Euler's number (approx. 2.718), representing exponential decay
Step-by-Step Example
1. Create the Kernel Weights
Let’s calculate the weights for a
- Center pixel (0, 0):
- Immediate horizontal and vertical neighbors (e.g.,
, , , ):
- Corner neighbors (e.g.,
, , , ):
2. Normalize the Weights
If we add up all the unrounded weights calculated above (1 center + 4 edges + 4 corners), the sum is roughly (
3. Apply the Filter (Convolution)
Imagine a section of your image has the following pixel values:
To find the new smoothed value for the center pixel, we multiply the image pixels by the Gaussian kernel weights and sum them up:
4. Result
The center pixel value is smoothed from
When to use ?
- Standard preprocessing before edge detection (e.g., before applying Sobel or Canny).
- Reducing Gaussian noise (random sensor noise from cameras).
- Any time you need smooth, natural-looking blurring.
How to pick ?
- Small
(e.g., 0.5–1.0): light smoothing, retains more detail. - Large
(e.g., 3–5+): heavy smoothing, more detail is lost. - Rule of thumb: kernel size should be approximately
(odd-numbered).
When to avoid ?
- On images with salt-and-pepper noise — Gaussian blur spreads isolated pixel outliers into the surrounding region.
- When edges must be completely preserved.
Gaussian blur is the default go-to, but choosing
3. Median Filter
Non-Linear Spatial
The median filter is normally used to
reduce noise in an image, like the mean filter, but it does better job in preserving details in the image in comparison.
How it works?
Median filter, sorts all pixel values in the neighborhood and replaces the center pixel with the median (middle) value.
By calculating the median value of a neighborhood, the median filter has two main advantages over the mean filter:
- Robust to outliers: The median is a more robust average than the mean and so a single/few outlier pixel(s) in a neighborhood will not affect the median value significantly.
- Preserving sharp edges: Since the median filter's pick value must actually be the value of one of the pixels in the neighborhood, the median filter does not introduce new intensity pixel (calculated value) when the filter straddles an edge, thus the median filter is much better at preserving sharp edges better.
When to use?
- Images corrupted by salt-and-pepper noise (random black and white pixels) — this is where the Median Filter excels.
- When you need noise removal but must preserve sharp edges.
- Applications: Scanned documents, binary images, or medical images with impulse noise.
When to avoid
-
Gaussian noise is characterized by small, random variations distributed across the entire image.
A median filter works by picking a single pixel value from a sorted neighborhood and if more than few pixels has a tiny amount of random noise, picking the median pixel will just selects a different noisy value.
A Gaussian filter is much better here because averaging mathematically cancels out zero-mean random noise, smoothing the image out beautifully. -
When computational speed is critical — sorting is more expensive than convolution which is computationally expensive, especially as the kernel size or image resolution grows.
-
If you run a median filter over an image multiple times, it continuously forces neighboring pixels to take on identical values. This destroys fine, low-contrast textures (like hair, fabric, or grass) and turns them into flat, artificial-looking blocks of color.
The Median Filter is non-linear — it cannot be described as a simple convolution. This means it does not combine cleanly with frequency-domain analysis. It also tends to erode thin lines or small features if the kernel is too large. Use kernel size 3×3 as a starting point.
4. Bilateral Filter
Non-Linear Spatial
Bilateral filtering is an edge-preserving smoothing technique used in image processing, meaning — reduce noise while maintaining sharp boundaries in an image.
How it works?
Bilateral Filter are based on two factors:
- Spatial distance: Like a regular Gaussian Filter, nearby pixels have higher influence on the output.
- Intensity similarity: Pixels with similar intensity (brightness) contribute more.
Bilateral Filter combines both, pixels that are spatially close AND have a similar intensity to the center pixel are blended together
Formula
The Core Components
: The new, filtered intensity value for the current pixel at position . : The local neighborhood (window) of pixels around the target pixel . : The original intensity of a neighboring pixel at position . : A normalization factor that ensures the weights sum up to 1, preventing the image from becoming unnaturally brighter or darker.
The Two Weights: Spatial Kernel, this is a standard Gaussian function. If the neighboring pixel is physically close to the target pixel , the weight is high. As you move further away in the window, the weight drops toward zero. : Intensity (range) Kernel, This is the edge-preserving element. It looks at the difference in brightness/color between the neighbor and the target. If the neighbor has a very similar intensity to the target, the weight is high. If there is a massive jump in intensity, the weight drops to near zero.
Key Features
mindmap root((Bilateral
Filter)) Edge Preservation Edge-Aware Smoothing Dual Gaussian Filters Spatial Gaussian Intensity Guassian Parameter Sensitivity Spatial
\sigma_s Intensity
\sigma_r Noise Reduction Computational
Complexity Gaussian
Spatial + Gaussian
Intensity
When to use
- Preserves edges excellently: When you need to denoise but must keep edges sharp (e.g., portrait smoothing, medical imaging).
- As a preprocessing step before edge detection on natural images. (Works well for natural images where boundaries are important)
- Produces visually sharper results compared to Gaussian blur
- Performs smoothing by adjusting the weight of each pixel based not only on its spatial distance but also its intensity difference from the target pixel.
Parameters to tune
(spatial): controls how far spatially neighbors influence the center. Larger = more spatial blending. (range/intensity): controls how different in intensity a pixel can be and still contribute. Smaller = stronger edge preservation.
When to avoid
- Real-time or embedded systems — the Bilateral Filter is significantly slower than gaussian filter.
- Very noisy images with large noise amplitudes — the range kernel may fail to distinguish noise from true edges.
- When edge sharpness is not a concern — Gaussian is simpler and faster.
Disadvantages
- Computationally Intensive: Bilateral Filter needs computing both, the intensity and spatial weights for each pixel (
) makes the bilateral filter slower than other smoothing filters like Mean and Gaussian filter, especially for large images. - Parameter Tuning: In this filter the parameter tuning for choosing appropriate values for the spatial and intensity sigma values can be tricky and requires experimentation for different images.
Bilateral filtering can create a "cartoon" or "plastic" appearance if over-applied, known as the HDR effect. It can also fail to separate noise from real edges when noise amplitude is large relative to the actual edge contrast.
5. Min & Max Filters
Non-Linear Spatial