Image Denoising (Generating Noisy Images)
Introduction
Recently, while studying computer vision, I encountered various image denoising techniques. In this series, I will mainly introduce traditional image denoising methods. Before diving into the denoising techniques, let’s first introduce some common noise types and evaluation metrics.
Introduction to Common Noises and Example Code
Before introducing the common noises, let’s start with our original image, which is also a classic image in the field of computer vision:
Gaussian Noise
Gaussian noise is simply random noise that follows a Gaussian distribution, whose probability density function is given by
$$ P(x) = \frac{1}{\sqrt{2\pi\sigma^2}} e^{-\frac{(x - \mu)^2}{2\sigma^2}} $$
where $\mu$ determines the mean of the noise and $\sigma^2$ determines the noise intensity. Note that Gaussian noise is generally assumed to be independently and identically distributed.
1 | def add_gaussian_noise(image, mean=0, std=25): |
Example:
Salt and Pepper Noise
Salt and pepper noise refers to noise where some pixels are randomly set to the maximum value (salt) or the minimum value (pepper), often used to simulate noise due to transmission errors or sensor dirt. Salt and pepper noise does not have an explicit probability density function; instead, the probability $p$ is used to control the occurrence of noisy pixels.
1 | def add_salt_pepper_noise(image, prob=0.05): |
Example:
Poisson Noise
Poisson noise, also known as “shot noise” or “granular noise”, is generated by the random arrival of photons in a photodetector, and its characteristics are related to the signal intensity. Poisson noise is signal-dependent and is commonly observed in low-light imaging. Its distribution follows the Poisson distribution: $P(k) = \frac{\lambda^{k} e^{-\lambda}}{k!}$
where $\lambda$ is the original pixel value and $k$ is the noisy pixel value.
1 | def add_poisson_noise(image): |
Example:
Multiplicative Noise
Multiplicative noise is noise that is proportional to the signal intensity. A common model is:
$$ g(x, y) = f(x, y) · \eta(x,y) \qquad \eta \sim U[a,b]$$
Of course, $\eta$ can also follow a Gaussian distribution with mean 0, which is the typical speckle noise.
1 | def add_multiplicative_noise(image, mean=0, std=0.1): |
Example:
Uniform Noise
Uniform noise is an additive noise that follows a uniform distribution:
$$ g(x, y) = f(x, y) + \eta(x,y) \qquad \eta \sim U[a,b]$$
1 | def add_uniform_noise(image, low=-50, high=50): |
Example:
周期噪声
Periodic noise is caused by electronic interference and manifests as a regular sinusoidal noise pattern:
$$ n(x, y) = A · \sin(2\pi (ux + vy) + \phi) $$
where $A$ is the amplitude, $u$ and $v$ are the frequencies, and $\phi$ is the phase.
1 | def add_periodic_noise(image, frequency=50, amplitude=50): |
Example:
Mixed Noise
Mixed noise is simply a combination of several common noise types.
1 | def add_mixed_noise(image): |
Example:
Metrics
PSNR (Peak Signal-to-Noise Ratio)
- Formula:
$$ \text{PSNR} = 20 \log_{10}\left(\frac{255}{\sqrt{\text{MSE}}}\right) $$ - Meaning:Quantifies pixel-level differences; a higher value (typically >30dB) indicates better denoising performance.
- Characteristics:Simple calculation, but not sensitive to human visual perception.
SSIM(结构相似性指数)
Formula:
The product of three components: luminance ($\mu$), contrast ($\sigma$), and structure ($\sigma_{xy}$):
$$
\text{SSIM} = \frac{(2\mu_x\mu_y + C_1)(2\sigma_{xy} + C_2)}{(\mu_x^2 + \mu_y^2 + C_1)(\sigma_x^2 + \sigma_y^2 + C_2)}
$$- $\mu_x, \mu_y$: Mean of the images (luminance)
- $\sigma_x, \sigma_y$: Standard deviation (contrast)
- $\sigma_{xy}$: Covariance (structural similarity)
- $C_1=(k_1L)^2, C_2=(k_2L)^2$: Constants (with $L$ as the pixel range, typically $k_1=0.01, k_2=0.03$)
Meaning:Ranges from [0,1]; closer to 1 indicates better structural preservation.
Characteristics:Provides a comprehensive evaluation of texture, edge, and contrast preservation.
MSE(Mean Squared Error)
- Formula:
$$ \text{MSE} = \frac{1}{N}\sum (x_i - y_i)^2 $$ - Meaning:Directly reflects the average pixel difference; lower values are better.
- Characteristics:Ignores spatial structure and is sensitive to outliers.
EPI(Edge Preservation Index)
- Formula:
$$ \text{EPI} = \frac{\sum|\nabla\text{denoised} - \nabla\text{original}|}{\sum|\nabla\text{original}|} $$ - Meaning:Evaluates the ability to preserve edges; lower values (ideally 0) indicate less detail loss.
- Characteristics:Specifically used for detecting edge blurring, but sensitive to the type of noise.
LPIPS(Learned Perceptual Image Patch Similarity)
- Principle:Based on the feature distance of a pre-trained VGG network.
$$ \text{LPIPS} = |\phi(x) - \phi(y)|_2 $$ - Meaning:Lower values indicate closer visual similarity, reflecting high-level semantic similarity.
- Characteristics:Computationally complex, requires GPU, and depends on deep learning models.
指标对比
Metric Type | Representative Metric | Core Meaning | Computational Complexity |
---|---|---|---|
Pixel Difference | PSNR/MSE | Global pixel error | Low |
Structural Similarity | SSIM | Texture/edge preservation | Medium |
Edge Preservation | EPI | Degree of detail loss | Medium |
Perceptual Quality | LPIPS | Visual similarity (human perception) | High |
1 | import cv2 |