Filtering: Gaussian Smoothing, Noise Removal, and Edge Effects¶
Noise Removal by Averaging¶
Adding Gaussian noise to an image: \(I'(x,y) = I(x,y) + \eta(x,y)\) where \(\eta \sim \mathcal{N}(0, \sigma^2)\). The noise sigma must be proportionate to the image range (e.g., \(\sigma=5\) for [0,255], \(\sigma=0.02\) for [0,1]).
To remove noise, replace each pixel with a local weighted average (moving average). This relies on two assumptions:
The true pixel value is similar to nearby pixel values (spatial correlation).
Noise at each pixel is independent and zero-mean, so averaging reduces noise.
Noise is generally not recoverable because we don’t know the exact noise realization — only its statistics. If additive noise causes clipping (exceeds [0,255] range), information is permanently lost.
Weighted Moving Average¶
Uniform weights (box filter) give equal influence to all neighbors. Non-uniform weights (higher in center, lower at edges) are preferable because closer pixels are more correlated with the center pixel.
Example: weights [1, 4, 6, 4, 1] / 16 produce smoother results than [1, 1, 1, 1, 1] / 5.
Filter kernels are typically odd-sized (e.g., 3x3, 5x5) so there is a well-defined center pixel.
2D Moving Average¶
For a 2D box filter of size \((2k+1) \times (2k+1)\):
Cross-Correlation¶
Generalized with non-uniform weights (kernel H):
The kernel H (also called mask, filter, or coefficients) is the matrix of weights applied at each position.
Gaussian Filter¶
A box filter produces visible artifacts (hard edges in blurred output). A Gaussian kernel provides smooth, natural blurring:
This is a circularly symmetric (isotropic) function. The normalization constant \(\frac{1}{2\pi\sigma^2}\) only affects brightness, not the blur shape.
Parameters¶
Sigma (σ): Controls the amount of blur. Larger σ = more smoothing. This is the important parameter.
Kernel size: Must be large enough to represent the Gaussian adequately. A small kernel truncates the tails.
Both kernels below have σ=5, but one is 10x10 and the other 30x30 — the larger representation is more accurate.
MATLAB/Octave¶
hsize = 31;
sigma = 5;
h = fspecial('gaussian', hsize, sigma);
output = imfilter(img, h);
Different sigmas yield different blur amounts:
h1 = fspecial('gaussian', 31, 1); % minimal blur
h2 = fspecial('gaussian', 31, 3); % moderate blur
h3 = fspecial('gaussian', 31, 10); % heavy blur
Two Sigmas: Noise vs Smoothing¶
Noise σ: variance of the additive noise (intensity domain). Larger = noisier image.
Filter σ: spatial width of the Gaussian kernel (spatial domain). Larger = more blurring/smoothing.
These are independent parameters. Effective denoising requires filter σ matched to the noise level — more noise demands more smoothing, at the cost of detail.
Gaussian Filter Properties¶
σ defines the blur scale with respect to the image.
The normalization constant affects only overall brightness, not blur character.
Altering kernel size without changing σ affects accuracy of representation, not blur amount.