Bitonic filter¶
| Fact | Value |
|---|---|
| Also called | Bitonic smoothing, Treece bitonic filter |
| Status | Implemented and tested |
| Family | Nonlinear spatial filters |
| Engine | Science engine |
| Type | Nonlinear, morphological, rank and linear combination |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | about 1.7 x length |
| Code | engine/src/pixelnexus_engine/filters/bitonic.py, bitonic |
| Operator code | engine/src/pixelnexus_engine/filters/bitonic.py, bitonic_representation |
| Packages | SciPy |
Overview¶
The bitonic filter, by Treece, smooths like a Gaussian but keeps edges. It rests on a simple idea of what signal is. A signal is bitonic within the filter's reach: it rises to at most one peak, or falls to at most one dip, and anything else is noise. This depends only on the order of the values, not on their size. So the filter keeps edges of any height and needs no setting for the noise level. It combines rank filters with a Gaussian. The filter runs in the PixelNexus engine, in PixelNexus's own code.
How it works¶
- Take the c-th and the (100 - c)-th centile of each disk of diameter l.
- Filter each again with the other centile, to get the centile opening and closing.
- Smooth the difference between the input and each with a Gaussian of sigma 0.33 l.
- Mix the opening and closing, each weighted by the other's smoothed error.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(r_c\): The rank filter at the c-th centile over the disk
- \(O, C\): The centile opening and closing
- \(G_\sigma\): A Gaussian with sigma 0.33 l
- \(e_O, e_C\): The smoothed errors of the opening and the closing
- \(b\): The output
r_c is a rank filter that takes the c-th centile in a disk of diameter l. With a low c, r_c then r_(100-c) is a centile opening, which keeps dips and removes peaks narrower than the disk. The closing does the reverse. A bitonic signal survives one of them unchanged. The errors of each against the input, smoothed with a Gaussian of sigma 0.33 l, show which fits better nearby, and the output weighs each by the other's error. Where both errors are 0, both weights are set to 0.5. In heavy noise, the opening and closing become nearly flat, and the output tends to the Gaussian of the input.
A morphological opening keeps dips and removes peaks narrower than its disk. A closing does the reverse. Treece uses centile versions, with a low centile c in place of the minimum and 100 - c in place of the maximum, so that small impulses are rejected too. A bitonic signal survives one of the two unchanged. To choose between them, the filter compares each with the input. A point by point comparison would only give back the input, so the differences are smoothed with a Gaussian first. Where the opening fits worse, the closing gets more weight, and the other way round.
In heavy noise, the opening and closing become nearly flat, one below the mean and one above. The weighted mix then reduces to the Gaussian of the input. So the filter never does worse than its Gaussian part by much, and it adds no new kind of artifact.
Kernel or operator¶
There is no single kernel. The rank filters use a disk of diameter l, and the Gaussian has sigma 0.33 l and reaches 2 sigma. The Inspector asks the engine for the stages with the current settings.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Filter length l length |
9 | 3 to 31 px | The diameter l of the disk for the rank filters. The Gaussian has sigma 0.33 l. Our choice of 9. |
Centile c centile |
10 | 0 to 25 % | The low centile c of the opening and closing. The report uses 10 for noisy images and 2 for clean ones. |
Channels channelScope |
RGB | RGB, Each channel separately, Brightness only, Color only | Which part of the color image the filter changes. |
Implementation¶
bitonic in engine/src/pixelnexus_engine/filters/bitonic.py follows the equations of Treece's technical report. The rank filters are scipy.ndimage.percentile_filter over a disk with dx^2 + dy^2 <= (l / 2)^2. The Gaussian is scipy.ndimage.gaussian_filter with sigma 0.33 l, cut at 2 sigma, as in the report's tests. The image is extended symmetrically at its edges, as the report does. Where both smoothed errors are 0, both weights are set to 0.5, as in the report's note on that case. The default length of 9 is our choice.
Worked example¶
The step and lines of the figure, 120 x 120:
| Noise sigma | Noisy (dB) | Gaussian (dB) | Median (dB) | Bitonic (dB) |
|---|---|---|---|---|
| 5 | 34.15 | 21.46 | 21.22 | 21.53 |
| 10 | 28.15 | 21.45 | 21.26 | 21.85 |
| 20 | 22.15 | 21.41 | 21.23 | 22.28 |
| 40 | 16.44 | 21.26 | 20.98 | 21.97 |
The disk and square of the edge detector pages, 160 x 160, blurred with a Gaussian of sigma 1.5 before noise:
| Noise sigma | Noisy (dB) | Gaussian (dB) | Median (dB) | Bitonic (dB) |
|---|---|---|---|---|
| 5 | 34.20 | 32.52 | 42.50 | 43.57 |
| 10 | 28.19 | 32.46 | 39.53 | 41.21 |
| 20 | 22.21 | 32.15 | 35.35 | 37.29 |
| 40 | 16.82 | 30.73 | 30.71 | 32.22 |
PSNR against the image before noise, with Gaussian noise rounded and clipped to 8 bits. All three filters use l = 9, and the bitonic filter c = 10 percent.
On the disk and the square, the bitonic filter beats both the median and the Gaussian at every noise level, by 1.1 to 2.0 dB over the median. On the step with thin lines, every filter loses most of the line contrast, so the scores are close. The figure still shows the difference: only the bitonic filter keeps the lines. At sigma 5, a length of 9 smooths more than the noise needs, and all three filters score below the noisy input. A smaller length suits weak noise.
Complexity¶
- Time: \(O(N l^2)\)
- Memory: \(O(N)\)
N is the number of pixels. The report says it takes 3 to 4 times as long as one rank filter of the same size.
Artifacts and limitations¶
Limitations
- Features narrower than the disk with both a peak and a dip, such as fine texture, are smoothed away.
- Slower than a Gaussian, since it runs four rank filters.
Artifacts
- Single stair-step pixels on pixelated curved outlines can change.
- Flattened thin lines and small spots at large lengths.
Tests¶
The disk of diameter 9 must hold 69 pixels. The opening, the closing and the smoothed errors must match direct calls of the SciPy filters, and the output must follow the weighting equation. Where both errors are 0, both weights must be 0.5. A straight step must pass unchanged, and so must the inside of a ramp. A single impulse must stay with c = 0 and go with c = 10. At sigma 5 and 20, the filter must beat the median, which must beat the Gaussian. On pure strong noise, the output must stay close to the Gaussian.
References¶
- Treece, G. The bitonic filter. Linear filtering in an edge-preserving morphological framework. IEEE Transactions on Image Processing 25(11), 5199 to 5211, 2016. DOI 10.1109/TIP.2016.2605302.
- Treece, G. The bitonic filter. Linear filtering in an edge-preserving morphological framework. Technical report CUED/F-INFENG/TR 700, University of Cambridge, 2015. https://www.repository.cam.ac.uk/handle/1810/252987