Joshu Leonardy
画 · 像 · 復 · 元

Image Restoration Lab

Labs 02–04 were about enhancement: making an image look better, judged by eye. Restoration has a stricter goal. It assumes the image was damaged in a known way and tries to undo that damage, and the result can be measured against the original. This lab follows Chapter 5 of Gonzalez & Woods: first model the noise, then remove it, then model the blur, and finally undo the blur and the noise together.

g(x, y) = (h ★ f)(x, y) + η(x, y)   ⇔   G(u, v) = H(u, v)F(u, v) + N(u, v)

The whole chapter rests on this one model (the book's eqs. 5-1 and 5-2). The true image f is blurred by a degradation function h, and then noise η is added. Sections 01–02 deal with noise only, where h does nothing. Sections 03–05 add the blur back in. Images are cropped and resized to 256 × 256 here, because the later sections work in the frequency domain, as in lab 04.

— 01 —
雑 · 音 · 模 · 型

Noise models, and measuring them

Gonzalez & Woods, 4th ed. §5.2: Some Important Noise Probability Density Functions (p. 319), Estimating Noise Parameters (p. 325), eqs. 5-3 to 5-20

Every noise model is a probability density function (PDF) describing the values η can take. In practice you are not told which PDF applies. You find a region of the image that should be perfectly flat, such as a wall, the sky or a uniform background, and look at its histogram. Any spread in that histogram must be noise. Drag a box over the image to choose the region. The curve drawn over the histogram is the true PDF, so you can check the estimate against it.

The estimates come from the patch alone. They are the mean and variance of its histogram (eqs. 5-19 and 5-20). If the patch really is flat, its mean is the true brightness plus the noise mean, and its variance is the noise variance. If you drag the box across an edge, the edge's own variation gets counted as noise too.

Noise PDF
Sample
Noisy image · drag a box over a flat region
Histogram of the patch · line = true PDF, shifted to the patch's clean brightness
— 02 —
平 · 均 · 化 · 濾 · 波

Mean filters, and one that adapts

Gonzalez & Woods, 4th ed. §5.3: Mean Filters (p. 328), Order-Statistic Filters (p. 330), Adaptive Filters (p. 333), eqs. 5-23 to 5-32

Lab 03 compared the ordinary average with the median. Chapter 5 adds several other means, and each one handles impulses differently. The contraharmonic mean is the one to try first. With Q > 0 it removes pepper (black dots), and with Q < 0 it removes salt (white dots). Choose the wrong sign and it makes the image much worse. The adaptive filter goes further: it uses local statistics to decide, pixel by pixel, how much smoothing to apply.

Point at the image to see the numbers in the window.
Noise
Window
Filter
Order Q
Trim d
Assumed noise variance σ²η
PSNR against the clean image · same window, every filter
— 03 —
劣 · 化 · 関 · 数

Modelling the blur: H(u, v)

Gonzalez & Woods, 4th ed. §5.5 Linear, Position-Invariant Degradations (p. 348); §5.6: Estimation by Modeling (p. 353), eqs. 5-68 and 5-77

To undo a blur you first need H. The book gives two physical models. One is atmospheric turbulence, which blurs everything smoothly. The other is uniform linear motion, where the camera moves a distance (a, b) while the shutter is open. Motion blur has a telltale sign: H falls exactly to zero along evenly spaced lines. At those frequencies the blur has erased the image information completely, and that will matter in section 04.

The book writes the motion model with a and b as fractions of the image size. Here they are measured in pixels, so ua becomes ua/256. After blurring, noise with standard deviation σ is added and the result is rounded to 8 bits, as a real camera would do. That means even σ = 0 leaves some noise, from rounding.

Model
Noise σ
|H(u, v)| centred · black = zero
Cross-section |H(u, 0)| · log scale
— 04 —
逆 · 濾 · 波

Inverse filtering, and why it explodes

Gonzalez & Woods, 4th ed. §5.7 Inverse Filtering (p. 356), eqs. 5-78 and 5-79

If the damage was multiplication by H, the obvious fix is to divide by it. That is exactly right for the blur, but it also divides the noise by H. Wherever H is tiny, even a small amount of noise gets multiplied into a huge error. The book's workaround is to divide only near the centre of the spectrum, inside a radius D0, where H is still large.

F̂(u, v) = G(u, v) / H(u, v) = F(u, v) + N(u, v) / H(u, v)

The second form is the book's eq. 5-79, and it explains the whole problem: even with H known exactly, you get back F plus a term you can never know, the noise divided by H. The cutoff here multiplies the inverse by a Butterworth lowpass of order 10, which is how the book's own example limits the division to a radius.

Cutoff radius D₀
Gain of the restoration filter along u · log scale · dashed = |H|
— 05 —
最 · 適 · 復 · 元

Wiener and constrained least squares

Gonzalez & Woods, 4th ed. §5.8 Minimum Mean Square Error (Wiener) Filtering (p. 358), eqs. 5-83, 5-85; §5.9 Constrained Least Squares Filtering (p. 363), eqs. 5-89 to 5-98

Both filters fix the inverse filter by adding one term to the denominator, which keeps it away from zero. Wiener adds a constant K, which stands in for the noise-to-signal power ratio. Constrained least squares adds γ|P|², where P is the Laplacian, so it holds back exactly the frequencies that would make the result rough. The difference is in how the parameter is chosen. The book offers no rule for K, so you tune it by eye. For γ it gives an iteration that needs only the noise variance, which you can measure as in section 01.

Method
K
γ
Choose the parameter
Degraded
Inverse (section 04)
Wiener
Constrained least squares
Gain of each restoration filter along u · log scale
Neither filter can bring back what H destroyed. Wherever H = 0, the degraded image holds no trace of the original at that frequency, and every method has to fill those gaps with something smooth. Restoration recovers what the blur only weakened. What the blur erased is gone.