Skip to content

Robust M-estimator filter

Fact Value
Also called M-estimator smoothing, Huber filter, Tukey biweight filter, Robust mean filter
Status Implemented and tested
Family Adaptive and statistical filters
Engine Science engine
Type Nonlinear, statistical, M-estimate of location
Output Image
Operator shown as algorithm (exact)
Support radius radius
Code engine/src/pixelnexus_engine/filters/robust.py, m_estimator
Operator code engine/src/pixelnexus_engine/filters/robust.py, m_estimator_representation
Packages scikit-image, SciPy
Channels RGB, Brightness only, Color only

Overview

The M-estimator filter replaces each pixel with a robust mean of its window. Pixels far from the current estimate count less, or not at all. So impulse noise and the pixels on the other side of an edge barely pull the result. It sits between the mean, which every pixel pulls, and the median, which ignores how far pixels are. The filter runs in the PixelNexus engine, with our own code.

Four panels. A bright disk and gray square on a dark ground, covered with fine noise and many black and white dots. The 5 by 5 median, the Tukey result and the Huber result all show clean shapes with sharp edges and almost no dots. Four panels. A bright disk and gray square on a dark ground, covered with fine noise and many black and white dots. The 5 by 5 median, the Tukey result and the Huber result all show clean shapes with sharp edges and almost no dots.
A disk and a square with Gaussian noise of sigma 10 and 10 percent of pixels set to black or white. Then a 5 x 5 median, and the M-estimator with Tukey and with Huber weights, both with a scale of 10.

How it works

  1. Start with the median of the window.
  2. Weigh each window pixel by how far it is from the estimate, in units of the scale.
  3. Take the weighted mean as the new estimate.
  4. Repeat for the given number of steps.

Mathematical foundation

\[ \hat\mu = \arg\min_\mu \sum_{q \in W} \rho\!\left(\frac{I_q - \mu}{s}\right), \qquad \mu_{t+1} = \frac{\sum_q w(r_q)\, I_q}{\sum_q w(r_q)},\quad r_q = \frac{I_q - \mu_t}{s} \]

The formula shows the default parameter values.

where

  • \(\hat\mu\): The robust estimate at the pixel
  • \(\rho\): The loss of the estimator
  • \(w\): The weight of a window pixel
  • \(s\): The scale
  • \(W\): The window

An M-estimator picks the value mu that makes the sum of rho of the scaled residuals smallest. With rho the square, that is the mean. With rho the absolute value, it is the median. Huber's rho is a square near 0 and grows only linearly beyond k, so outliers pull less. Tukey's biweight stops growing beyond c, so far outliers stop pulling at all. Holland and Welsch solve this by iteratively reweighted least squares. Each step weighs every pixel by w = rho' (r) / r and takes the weighted mean. Huber's weight is min(1, k / |r|) with k = 1.345. Tukey's is (1 - (r / c)^2)^2 inside c = 4.685 and 0 outside. These are the usual constants for 95 percent efficiency at the normal distribution.

Huber proposed estimators that behave like the mean for small residuals and like the median for large ones. Tukey's biweight goes further and gives far residuals no weight at all. Neither has a closed form, so each step reweighs the pixels by the current residuals and takes the weighted mean. Holland and Welsch made this iteratively reweighted least squares a standard tool. A redescending estimator such as Tukey's needs a good start, so the filter starts from the median.

Kernel or operator

There is no fixed kernel. The Inspector asks the engine for the stages with the current settings.

Parameters

Parameter Default Values Meaning
Weights estimator Huber Tukey biweight, Huber Huber's weights shrink the pull of far pixels but never reach 0. Tukey's biweight drops pixels beyond c times the scale. Huber is our choice of default, since it scored higher on the worked example.
Scale scale 0 0 to 100 levels The scale s that residuals are divided by, about the noise sigma. 0 estimates it from the channel with scikit-image's estimate_sigma.
Radius radius 2 1 to 7 px The window reaches this far in each direction, so 2 gives a 5 x 5 window. Our choice.
Iterations iterations 5 1 to 20 The number of reweighting steps after the median start. Our choice.
Channels channelScope RGB RGB, Brightness only, Color only Which part of the color image the filter changes.

Implementation

m_estimator in engine/src/pixelnexus_engine/filters/robust.py runs on each plane of the channel scope. It starts from the window median, then reweighs for the given number of steps. Where all weights in a window are 0, which only Tukey's weights allow, the pixel keeps its last estimate. With a scale of 0, the filter estimates it from the channel with skimage.restoration.estimate_sigma.

Worked example

Weights Scale PSNR (dB)
Median 5 x 5 36.94
Tukey auto 36.46
Tukey 5 35.61
Tukey 10 35.65
Tukey 20 36.96
Tukey 40 35.21
Huber auto 35.78
Huber 5 37.51
Huber 10 37.64
Huber 20 36.56
Huber 40 34.00

The image of the figure, with a 5 x 5 window and 5 steps. The PSNR compares the result with the image before the noise. The noisy input scores 14.59 dB.

The best result here is Huber's at a scale of 10, the sigma of the Gaussian noise, with 37.64 dB against 36.94 dB for the median. Tukey does not beat the median on this image, except by 0.02 dB at a scale of 20. The automatic scale comes out at 25 levels here, since the impulses inflate the noise estimate, so it does worse than a scale set by hand. Set the scale near the Gaussian noise sigma when you know it.

Complexity

  • Time: \(O(N R^2 K)\)
  • Memory: \(O(N R^2)\)

N is the number of pixels, R the window side and K the number of steps.

Artifacts and limitations

Limitations

  • The scale matters. Too large and it acts like a mean, too small and it keeps the noise.
  • Fine detail smaller than the window is lost.

Artifacts

  • Small flat patches where Tukey's weights drop a whole cluster.

Tests

Huber's and Tukey's weights must match their formulas. The result must match a direct reweighting loop to 1e-12. On a step with Gaussian noise and impulses, Tukey must beat the 5 x 5 median and keep the edge. A pixel whose weights are all 0 must keep its estimate. The representation must have its three stages.

References

  • Huber, P. J. Robust estimation of a location parameter. The Annals of Mathematical Statistics 35(1), 73 to 101, 1964. DOI 10.1214/aoms/1177703732.
  • Beaton, A. E., and Tukey, J. W. The fitting of power series, meaning polynomials, illustrated on band-spectroscopic data. Technometrics 16(2), 147 to 185, 1974. DOI 10.1080/00401706.1974.10489171.
  • Holland, P. W., and Welsch, R. E. Robust regression using iteratively reweighted least-squares. Communications in Statistics, Theory and Methods 6(9), 813 to 827, 1977. DOI 10.1080/03610927708827533.