๐ง Noise Estimation in a Single Image โ Tutorial
๐ง Noise Estimation in a Single Image โ Tutorial
๐ฏ Goal
Estimate the noise variance or noise standard deviation (ฯ) from an image $g(x, y) = f(x, y) + \eta(x, y)$, where $f$ is the clean image and $\eta$ is additive noise.
We often assume zero-mean white Gaussian noise, i.e., $\eta \sim \mathcal{N}(0, \sigma^2)$.
๐ Common Methods
๐ก 1. High-Pass Filtering Method (Residual-Based)
Assumption: Noise is high-frequency, image content is mostly low-frequency.
๐ Steps:
- Apply a Gaussian blur to remove low-frequency content.
- Subtract blurred image from original to isolate residual (mostly noise).
- Compute the standard deviation of this residual.
๐งช Code (OpenCV/Numpy):
import cv2
import numpy as np
def estimate_noise_highpass(img):
img = img.astype(np.float32)
blurred = cv2.GaussianBlur(img, (7, 7), 1.5)
residual = img - blurred
return np.std(residual)
img = cv2.imread('image.png', 0) # grayscale
sigma_est = estimate_noise_highpass(img)
print(f"Estimated noise std: {sigma_est:.2f}")
๐ก 2. MAD on Wavelet Detail Coefficients
MAD: Median Absolute Deviation
๐ Steps:
- Apply a wavelet decomposition (e.g., using Haar or Daubechies).
- Use high-frequency subbands (e.g., horizontal, vertical, diagonal).
- Estimate ฯ from detail coefficients:
This formula works for Gaussian noise due to properties of MAD.
๐งช Code (PyWavelets):
import pywt
import numpy as np
import cv2
def estimate_noise_wavelet(img):
coeffs = pywt.dwt2(img, 'db1')
_, (cH, cV, cD) = coeffs
detail_coeffs = np.concatenate([cH.ravel(), cV.ravel(), cD.ravel()])
sigma = np.median(np.abs(detail_coeffs)) / 0.6745
return sigma
img = cv2.imread('image.png', 0)
sigma_wavelet = estimate_noise_wavelet(img.astype(np.float32))
print(f"Estimated noise ฯ (wavelet): {sigma_wavelet:.2f}")
๐ก 3. Flat Patch Analysis
Assume flat regions (low gradient) contain mostly noise.
๐ Steps:
- Divide image into blocks (e.g., 8ร8)
- Compute local variance for each patch
- Keep patches with low edge activity (low gradient or entropy)
- Estimate noise as mean or median variance of flat patches
This method is robust to structured content.
๐ก 4. Blind Estimators (No Training)
๐ Method by Immerkaer (1996) โ uses Laplacian
\[\sigma \approx \sqrt{\frac{\pi}{2}} \cdot \frac{1}{6(N-2)(M-2)} \sum_{x=2}^{N-1} \sum_{y=2}^{M-1} |(g * \nabla^2)(x, y)|\]Where $\nabla^2$ is the Laplacian kernel:
\[\begin{bmatrix} 0 & 1 & 0 \\ 1 & -4 & 1 \\ 0 & 1 & 0 \end{bmatrix}\]๐ฌ When to Use What?
Method | Strengths | Weaknesses |
---|---|---|
High-pass residual | Fast, simple | Sensitive to textures |
Wavelet MAD | Robust, well-founded | Needs wavelet lib |
Flat patch variance | Good for natural images | Needs threshold tuning |
Laplacian estimator | Fully blind, elegant | Assumes Gaussian noise |
โ Summary
- If you want a quick estimate: use high-pass filtering or wavelet-MAD.
- For robust methods: wavelet-based MAD is commonly used in denoising papers.
- Noise estimation is essential for adaptive filters (Wiener, BM3D, DnCNN).