Adaptive Wiener filter¶
| Fact | Value |
|---|---|
| Also called | Local Wiener filter, Lee local statistics filter |
| Status | Implemented and tested |
| Family | Adaptive and statistical filters |
| Engine | Browser |
| Type | Nonlinear, statistical, local linear estimator |
| Output | Image |
| Operator shown as | estimator (exact) |
| Support radius | floor(size / 2) |
| Code | web/src/core/filters/adaptive/local-noise.ts, wienerAdaptiveFilter |
| Operator code | web/src/core/filters/adaptive/local-noise.ts, localNoisePlane |
| Channels | RGB, Brightness only |
Overview¶
The adaptive Wiener filter moves each pixel toward the mean of its window by an amount that depends on how much the window varies. Where it varies about as much as the noise, the window is taken as flat and the pixel becomes the mean. Where it varies much more, there is real detail, and the pixel is kept. So flat areas are smoothed and edges stay.
How it works¶
- Find the mean m and the variance s^2 of the window.
- Compare s^2 with the noise variance n^2.
- Move the pixel toward m by the share n^2 / s^2, or all the way when s^2 is not larger than n^2.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(m\): The local mean
- \(s^2\): The local variance
- \(n\): The noise standard deviation
- \(z\): The pixel value
m and s squared are the mean and variance of the window, z is the pixel and n is the noise sigma. Where the window varies about as much as the noise, the gain is near 0 and the output is the local mean. Where it varies much more, there is real detail, the gain is near 1 and the pixel is kept. This is the estimate of Lee (1980) for additive noise, in the form of MATLAB's wiener2 and scipy.signal.wiener. Those estimate n squared from the whole image when it is not given. Here it is a parameter, so a strip of the image gives the same result as the whole image.
Lee (1980) derived this estimate for an image with additive white noise: the best linear estimate of the signal from the local mean and variance. The signal variance is s^2 - n^2, and the gain is the signal variance over the total variance. The same formula is used by MATLAB's wiener2 and by scipy.signal.wiener. Those estimate n^2 as the mean of all local variances when it is not given. Here it is a parameter, so that a strip of the image gives the same result as the whole image.
Kernel or operator¶
There is no kernel. The Inspector shows the window and the statistic. The Rank stepper in the Learn panel shows the window values at any pixel, sorted, next to the value the filter gives there.
Algorithm¶
- Pad the image with the border mode.
- Compute the local mean and variance with running sums in float64.
- Compute the gain from the variance and the noise variance.
- Write the mean plus the gain times the difference between the pixel and the mean.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Window size size |
5 | 3 to 25, odd px | Width and height of the window for the local mean and variance. |
Noise sigma noise |
10 | 0 to 100 | The standard deviation n of the noise, in 8-bit levels. The filter uses n squared. |
Border mode border |
Reflect 101 (default) | 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 | Which part of the color image the filter changes. |
Implementation¶
localNoisePlane in web/src/core/filters/adaptive/local-noise.ts computes the local mean and variance with running sums in float64 and applies the gain. The adaptive local noise reduction filter uses the same function. The filter runs in the browser engine, in Web Workers, through the shared filter framework in web/src/core/filters/run.ts. It handles the border mode, the channel scope, alpha and the mapping to 8 bits. Each strip of the image gets a halo as wide as the support radius, so strips give exactly the pixels of a whole-image run.
Worked example¶
The mean is m = 61.556 and the variance s^2 = 126.469. With noise sigma 10, the noise variance is 100. The gain is (126.469 - 100) / 126.469 = 0.2093. The output is 61.556 + 0.2093 x (90 - 61.556) = 67.509. The bright center is pulled about 79 percent of the way to the mean.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(N)\)
N is the number of pixels per channel. Running sums make the cost independent of the window size.
Artifacts and limitations¶
Limitations
- Needs the noise level. Too low leaves noise, too high blurs detail.
- Assumes additive noise of the same strength everywhere.
Artifacts
- Noisy halos next to edges, where the local variance is high and the gain stays near 1.
Tests¶
The reference applies the same formula to NumPy windows. Before it is used, the script checks it against scipy.signal.wiener, which pads with zeros, in the constant mode, and checks that a huge noise level gives the box mean. The test covers two sizes and noise levels for all five border modes.
References¶
- Lee, J.-S. Digital image enhancement and noise filtering by use of local statistics. IEEE Transactions on Pattern Analysis and Machine Intelligence PAMI-2(2), 165 to 168, 1980. DOI 10.1109/TPAMI.1980.4766994.
- SciPy documentation, scipy.signal.wiener. https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.wiener.html