Skip to content

Wavelet Wiener filtering

Fact Value
Also called Locally adaptive wavelet Wiener filter, LAWML denoising, Mihcak wavelet denoising
Status Implemented and tested
Family Wavelet and multiscale filters
Engine Science engine
Type Nonlinear, transform, locally adaptive Wiener shrinkage
Output Image
Operator shown as transform (exact)
Support radius global
Code engine/src/pixelnexus_engine/filters/wavelets.py, wavelet_wiener
Operator code engine/src/pixelnexus_engine/filters/wavelets.py, wavelet_wiener_representation
Packages PyWavelets, SciPy
Channels RGB, Brightness only, Color only

Overview

Wavelet Wiener filtering removes Gaussian noise with a smooth gain instead of a cut. Like wavelet thresholding, it splits the image into wavelet subbands. Then it looks at the neighbors of each detail coefficient. If they hold no more energy than noise would give, the coefficient is turned down to near zero. If they hold much more, as along an edge or in a texture, it is kept almost whole. The filter runs in the PixelNexus engine on your computer.

Four panels: bright disks on a dark ground with grainy noise, then three results. BayesShrink is clean with faint blotches. Wiener with the smallest estimate is clean, with sharp disk edges. Wiener with a 9 by 9 window leaves a ring of grain along each disk edge. Four panels: bright disks on a dark ground with grainy noise, then three results. BayesShrink is clean with faint blotches. Wiener with the smallest estimate is clean, with sharp disk edges. Wiener with a 9 by 9 window leaves a ring of grain along each disk edge.
Disks with Gaussian noise of sigma 20, filtered by wavelet thresholding with BayesShrink, and by wavelet Wiener filtering with the smallest estimate and with a 9 x 9 window.

How it works

  1. Split each channel into a small low-pass copy and J levels of horizontal, vertical and diagonal details.
  2. Measure the noise from the finest diagonal details, unless you set it.
  3. For each detail coefficient, take the mean of the squared coefficients around it and subtract the noise variance. This estimates how much signal is there.
  4. Multiply the coefficient by the share of signal in signal plus noise.
  5. Rebuild the channel.

Mathematical foundation

\[ \hat{\sigma}_x^2(k) = \min_{W} \max\Big(0,\ \frac{1}{W^2} \sum_{j \in N_W(k)} w_j^2 - \sigma^2\Big), \qquad \hat{w}(k) = \frac{\hat{\sigma}_x^2(k)}{\hat{\sigma}_x^2(k) + \sigma^2}\, w(k), \qquad \hat{I} = \operatorname{IDWT}\big(a_J,\ \hat{w}\big), \quad J = 4 \]

The formula shows the default parameter values.

where

  • \(w(k)\): A detail coefficient at position k in its subband
  • \(N_W(k)\): The W x W window of coefficients around k, in the same subband
  • \(\hat{\sigma}_x^2(k)\): The estimated local variance of the signal
  • \(\sigma\): The standard deviation of the noise
  • \(a_J\): The approximation after J levels

Mihcak, Kozintsev, Ramchandran and Moulin model each detail coefficient w(k) as a Gaussian signal value plus Gaussian noise of variance sigma^2. Each signal value has its own variance sigma_x^2(k). Neighboring coefficients have similar variances, so the mean of w^2 over a W x W window N_W(k), minus sigma^2, estimates sigma_x^2(k). The max with 0 keeps the estimate from going negative. For a Gaussian signal in Gaussian noise, the estimate with the least mean squared error is w times the Wiener gain sigma_x^2 / (sigma_x^2 + sigma^2). With the first window option, the estimate is computed for W = 3, 5, 7 and 9, and the smallest is kept. Lukas, Fridrich and Goljan used this form of the filter. Where the neighborhood holds only noise, the gain is near 0. Where it holds strong edges or texture, the gain is near 1. The noise sigma comes from the median absolute value of the finest diagonal details divided by 0.6745, as in wavelet thresholding. The approximation a_J is kept.

The Wiener filter is the linear filter with the least mean squared error when the signal and the noise are Gaussian with known variances. A global Wiener filter uses one signal variance for the whole image, which smooths edges as much as flat areas. Wavelet coefficients of photos are not like that. They are small in most places and large along edges and in textures. Mihcak, Kozintsev, Ramchandran and Moulin gave each coefficient its own variance and estimated it from a small window around it. That needs no training and costs little, yet it adapts the gain to each place in each subband. A small window follows edges closely but gives a noisy estimate. A large window gives a steady estimate but carries edge energy into the flat areas next to the edge, so noise survives there. Keeping the smallest estimate over several windows reduces the second problem.

Kernel or operator

The Inspector asks the engine for the stages with the current settings. They are the analysis, the filter taps, the noise estimate, the local variance with its windows, the Wiener gain and the synthesis. The filter taps are those of wavelet thresholding.

Algorithm

  1. Split the channel with the 2-D discrete wavelet transform into an approximation and J levels of details.
  2. Estimate the noise sigma from the diagonal details of the finest level, unless it is set.
  3. In every detail subband, compute the mean of the squared coefficients in each window, for each window size.
  4. Subtract sigma squared, clip at 0, and keep the smallest estimate when there are several windows.
  5. Multiply each coefficient by its Wiener gain.
  6. Rebuild the channel with the inverse transform.

Parameters

Parameter Default Values Meaning
Wavelet wavelet Daubechies 4 (db4) Haar, Daubechies 2 (db2), Daubechies 4 (db4), Daubechies 8 (db8), Symlet 4 (sym4), Symlet 8 (sym8), Coiflet 1 (coif1), Coiflet 3 (coif3) The orthogonal wavelet. Its filter taps come from PyWavelets.
Levels levels 4 1 to 8 How many times the transform splits the low-pass part. It is capped at the deepest level the image size allows.
Window window Smallest of 3x3 to 9x9 Smallest of 3x3 to 9x9, 3 x 3, 5 x 5, 7 x 7, 9 x 9 The square neighborhood of coefficients that estimates the local signal variance. The first option computes it for 3x3, 5x5, 7x7 and 9x9 and keeps the smallest estimate.
Noise sigma sigma 0 0 to 100 The standard deviation of the noise, in pixel values. 0 estimates it from the finest diagonal details.
Border mode border Reflect Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap How pixels outside the image are filled when the window reaches past the edge.
Channels channelScope RGB RGB, Brightness only, Color only Which part of the color image the filter changes.

Implementation

wavelet_wiener in engine/src/pixelnexus_engine/filters/wavelets.py runs wavelet_wiener_plane on each channel the scope names. It uses pywt.wavedec2 and pywt.waverec2, and the noise estimate of wavelet thresholding. local_signal_variance computes the window means of the squared coefficients with scipy.ndimage.uniform_filter. It mirrors the subband at its edges. wiener_gain turns the variance into the gain. There is no live preview. The result arrives when you click Apply.

Worked example

Window PSNR in dB
3 x 3 30.15
5 x 5 30.33
7 x 7 29.94
9 x 9 29.55
Smallest of 3x3 to 9x9 31.15
Wavelet thresholding, BayesShrink 29.80

The PSNR against the clean disks, for the disks with Gaussian noise of sigma 20, 22.66 dB before the filter. The image and the noise are those of the wavelet thresholding example. The Wiener rows use the defaults: db4, 4 levels and the estimated noise sigma. The last row is wavelet thresholding with its defaults.

Level Mean gain h Mean gain v Mean gain d
1 0.064 0.077 0.045
2 0.175 0.215 0.134
3 0.349 0.319 0.279
4 0.520 0.532 0.398

The mean Wiener gain in each subband with the default settings. The estimated noise sigma is 18.41. Level 1 is the finest. The gains are lowest there, where the details are mostly noise, and highest at the coarsest level, where the disks put most of their signal.

Complexity

  • Time: \(O(N (L + K))\)
  • Memory: \(O(N)\)

N is the number of pixels, L the number of filter taps and K the number of window sizes. The window means are separable, so their cost does not grow with the window size.

Artifacts and limitations

Limitations

  • The model assumes white Gaussian noise of the same strength everywhere.
  • The decimated transform is not shift invariant, so small blotches near edges remain.
  • The minimum over windows also lowers the gain on weak true detail.

Artifacts

  • Noise left in a narrow band along strong edges, where the windows include the edge and raise the gain.
  • Faint blotches near edges, from the decimated transform.

Tests

The local variance is checked against explicit windows over a mirrored copy of the subband, built with NumPy. The tests cover windows of 3, 5 and 9, and the smallest of four sizes. The whole filter is checked against an independent pipeline: PyWavelets, the explicit windows and the Wiener gain written out in the test. They match to within 10^-9. More tests check that the gains stay from 0 to 1, that a flat image stays flat, and a full job through the engine API with its representation.

References

  • Mihcak, M. K., Kozintsev, I., Ramchandran, K., and Moulin, P. Low-complexity image denoising based on statistical modeling of wavelet coefficients. IEEE Signal Processing Letters 6(12), 300 to 303, 1999. DOI 10.1109/97.803428.
  • Lukas, J., Fridrich, J., and Goljan, M. Digital camera identification from sensor pattern noise. IEEE Transactions on Information Forensics and Security 1(2), 205 to 214, 2006. DOI 10.1109/TIFS.2006.873602.
  • Donoho, D. L., and Johnstone, I. M. Ideal spatial adaptation by wavelet shrinkage. Biometrika 81(3), 425 to 455, 1994. DOI 10.1093/biomet/81.3.425.
  • Lee, G. R., Gommers, R., Waselewski, F., Wohlfahrt, K., and O'Leary, A. PyWavelets. A Python package for wavelet analysis. Journal of Open Source Software 4(36), 1237, 2019. DOI 10.21105/joss.01237.