Skip to content

Lee filter

Fact Value
Also called Lee speckle filter
Status Implemented and tested
Family Adaptive and statistical filters
Engine Browser
Type Nonlinear, statistical, local linear estimator for multiplicative noise
Output Image
Operator shown as estimator (exact)
Support radius floor(size / 2)
Code web/src/core/filters/adaptive/speckle.ts, leeFilter
Operator code web/src/core/filters/adaptive/speckle.ts, leeWeight
Channels RGB, Brightness only

Overview

The Lee filter reduces speckle, the multiplicative grain of radar, sonar, ultrasound and laser images. It compares how much each window varies, relative to its brightness, with how much the speckle alone would make it vary. Where the two are close, the window is flat and the pixel becomes the window mean. Where the window varies more, there is an edge or a target, and the pixel is kept.

Three panels: disks with gray speckle, the Lee result with smooth areas and sharp disk edges, and a 7x7 box filter that blurs the edges. Three panels: disks with gray speckle, the Lee result with smooth areas and sharp disk edges, and a 7x7 box filter that blurs the edges.
The Lee filter smooths the speckle in flat areas and keeps the disk edges. The box filter blurs them.

How it works

  1. Find the mean and the standard deviation of the window, and their ratio C_I.
  2. Compute the weight W = 1 - C_u^2 / C_I^2, at least 0.
  3. Write the mean plus W times the difference between the pixel and the mean.

Mathematical foundation

\[ \hat{R} = m + W\,(z - m), \qquad W = \max\Bigl(0,\; 1 - \frac{C_u^2}{C_I^2}\Bigr) \]

The formula shows the default parameter values.

where

  • \(m\): The window mean
  • \(C_I\): The coefficient of variation of the window
  • \(C_u\): The coefficient of variation of the speckle
  • \(W\): The weight of the pixel

m is the window mean and C_I its coefficient of variation, the standard deviation over the mean. C_u is the coefficient of variation of the speckle. In a flat area, the window varies only by the speckle, C_I is close to C_u, and W is near 0, so the output is the mean. On an edge, C_I is much larger, W is near 1, and the pixel is kept. This is the Lee filter in the form of Lopes, Touzi and Nezry, with W limited to 0.

Speckle multiplies the clean value by a random factor with mean 1. Its coefficient of variation C_u, the standard deviation of the factor, is the same everywhere. So in a flat area the local coefficient of variation C_I, the window standard deviation over the window mean, is close to C_u. A window with an edge or a target varies more, and C_I is larger. Lee (1980) derived the weight from the linear minimum mean-square error estimate with a first-order approximation of the multiplicative model. Lopes, Touzi and Nezry write it with coefficients of variation, as here. A window that varies less than the speckle would give a negative weight, so W is limited to 0 and the output is the mean.

Kernel or operator

There is no kernel. The Inspector shows the formula with the current C_u. The Rank stepper in the Learn panel shows the window at any pixel next to the value the filter gives there.

Algorithm

  1. Pad the image with the border mode.
  2. Compute the mean and variance of each window with running sums.
  3. Compute C_I and the weight W.
  4. Write the mean plus W times the difference between the pixel and the mean.

Parameters

Parameter Default Values Meaning
Window size size 7 3 to 15, odd px Width and height of the window for the local statistics.
Speckle variation C_u cu 0.25 0.01 to 1 The coefficient of variation of the speckle, its standard deviation over its mean. For an L-look intensity image it is 1 over the square root of L.
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

leeFilter in web/src/core/filters/adaptive/speckle.ts gets the window mean and variance from localMoments, with running sums in float64, and applies leeWeight. The other speckle filters share this code. 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 rounding 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

\[ W = \begin{bmatrix} 96 & 121 & 104 & 88 & 112 \\ 108 & 93 & 131 & 99 & 101 \\ 85 & 117 & 150 & 106 & 94 \\ 110 & 102 & 90 & 124 & 97 \\ 99 & 114 & 105 & 92 & 118 \end{bmatrix} \]

The window mean is m = 106.24 and its standard deviation 14.627, so C_I = 14.627 / 106.24 = 0.1377. With C_u = 0.1, the weight is W = 1 - 0.1^2 / 0.1377^2 = 0.4724. The output for the center 150 is 106.24 + 0.4724 x (150 - 106.24) = 126.914.

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

  • Leaves speckle next to edges, where the window variation is high.
  • Needs the speckle variation C_u.

Artifacts

  • Noisy halos along edges, as wide as the window.

Tests

No common library has this filter, so the reference applies the same formulas to NumPy windows of an input whose values are all above 0. Before it is used, the script checks that C_u = 0 leaves the image unchanged. The test covers two window and C_u settings 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.
  • Lopes, A., Touzi, R. and Nezry, E. Adaptive speckle filters and scene heterogeneity. IEEE Transactions on Geoscience and Remote Sensing 28(6), 992 to 1000, 1990. DOI 10.1109/36.62623.