Sigma filter¶
| Fact | Value |
|---|---|
| Also called | Lee sigma filter |
| Status | Implemented and tested |
| Family | Adaptive and statistical filters |
| Engine | Browser |
| Type | Nonlinear, statistical, selective local mean |
| Output | Image |
| Operator shown as | estimator (exact) |
| Support radius | floor(size / 2) |
| Code | web/src/core/filters/adaptive/sigma.ts, sigmaFilter |
| Operator code | web/src/core/filters/adaptive/sigma.ts, sigmaValue |
| Channels | RGB, Brightness only |
Overview¶
The sigma filter averages only the neighbors whose values lie within k sigma of the center value, where sigma is the noise level. Neighbors across an edge differ by more, so they are left out, and the edge stays sharp. If too few neighbors are in range, the center is an isolated spot of noise, and it gets the mean of its eight neighbors instead.
How it works¶
- Find the window values within k sigma of the center value.
- If there are at least the minimum count, write their mean.
- Otherwise write the mean of the eight neighbors.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(z\): The center value
- \(k\sigma\): The half-width of the accepted range
- \(K\): The minimum count
- \(N_8\): The eight neighbors of the center
z is the center value and W the window. Only values within k sigma of z take part in the mean. Values across an edge differ from z by more than that, so they are left out, and the edge stays. If fewer than K values, the minimum count, are in range, z is an isolated spot of noise, and the output is the mean of its eight neighbors N_8.
Lee (1983) based the filter on the two-sigma probability: about 95 percent of Gaussian noise lies within 2 standard deviations of the mean. So the values within 2 sigma of the center are likely to belong to the same region. The rule for isolated spots removes single noisy pixels, which have no neighbors in their range. The filter is related to the bilateral filter, with a range weight that is 1 inside the range and 0 outside.
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.
- For each pixel, find the window values within k sigma of the center.
- If at least K are in range, write their mean.
- Otherwise write the mean of the eight neighbors.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Window size size |
5 | 3 to 15, odd px | Width and height of the window. |
Noise sigma sigma |
10 | 0.5 to 100 | The standard deviation of the noise, in 8-bit levels. |
Range factor k k |
2 | 0.5 to 4 | Values within k times sigma of the center are averaged. Lee uses 2, which holds about 95 percent of Gaussian noise. |
Minimum count minCount |
3 | 1 to 25 | When fewer values than this are in range, counting the center, the center is a spot of noise. |
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¶
sigmaValue in web/src/core/filters/adaptive/sigma.ts applies the rule to each window from gatherPlane. 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 center is z = 41. With sigma 10 and k = 2, the range is 21 to 61. The 15 dark values are in range, the 10 bright ones are not. Their mean is 40.400. A 5x5 box filter would give 104.32, pulled toward the bright side.
Complexity¶
- Time: \(O(N\,k^2)\)
- Memory: \(O(N)\)
N is the number of pixels per channel and k the window width.
Artifacts and limitations¶
Limitations
- Needs the noise level.
- Edges weaker than k sigma are smoothed.
Artifacts
- Slight posterization in smooth ramps, because values outside the range are skipped.
Tests¶
The reference applies the same rule to NumPy windows. Before it is used, the script checks that a huge range gives the box mean. The test covers three settings of size, sigma, k and the minimum count, for all five border modes.
References¶
- Lee, J.-S. Digital image smoothing and the sigma filter. Computer Vision, Graphics, and Image Processing 24(2), 255 to 269, 1983. DOI 10.1016/0734-189X(83)90047-6.