Stationary wavelet filtering¶
| Fact | Value |
|---|---|
| Also called | Undecimated wavelet filtering, Translation-invariant wavelet denoising, Cycle spinning |
| Status | Implemented and tested |
| Family | Wavelet and multiscale filters |
| Engine | Science engine |
| Type | Nonlinear, transform, translation-invariant wavelet shrinkage |
| Output | Image |
| Operator shown as | transform (exact) |
| Support radius | global |
| Code | engine/src/pixelnexus_engine/filters/wavelets.py, swt_denoise |
| Operator code | engine/src/pixelnexus_engine/filters/wavelets.py, swt_denoise_representation |
| Packages | PyWavelets |
| Channels | RGB, Brightness only, Color only |
Overview¶
Stationary wavelet filtering is wavelet thresholding without the subsampling. The usual wavelet transform keeps only every second coefficient at each level, so its result depends on where the image starts. Move the image by one pixel and the blotches near edges move in a different way. The stationary transform keeps every coefficient, so no position is favored, and the blotches average out. The filter offers a second method, cycle spinning, which thresholds a few shifted copies and averages them. The filter runs in the PixelNexus engine on your computer.
How it works¶
- Add a few rows and columns, so that each side is a multiple of 2^J.
- Split each channel with the stationary transform. Every subband keeps one coefficient per pixel.
- Measure the noise and choose the thresholds, as in wavelet thresholding.
- Shrink the detail coefficients and rebuild the channel.
- Remove the added rows and columns.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(I\): The input channel
- \(a_J\): The approximation after J levels
- \(h_j, v_j, d_j\): The horizontal, vertical and diagonal details of level j. Level 1 is the finest.
- \(\eta_T\): The shrink rule with threshold T
- \(S_s\): A circular shift by s = (s_y, s_x) pixels
- \(n\): The number of shifts in each direction for cycle spinning
- \(T\): The threshold, in pixel values
The decimated transform keeps every second coefficient at each level, so its result changes when the image moves by one pixel. The stationary transform, after Nason and Silverman, skips the subsampling. At level j its filters have 2^(j-1) - 1 zeros between their taps, so each subband has one coefficient per pixel. The thresholds, the noise estimate and the shrink rule eta_T are those of wavelet thresholding, applied to these coefficients. White noise keeps its sigma in every subband, since the filters have unit energy. Coifman and Donoho called this translation-invariant denoising. They showed that it equals cycle spinning over all shifts: shift the image by s, threshold it with the decimated transform, shift it back by -s, and average. S_s shifts by s in a circle. With J levels, 2^J shifts in each direction cover all the cases. Cycle spinning with fewer shifts averages only some of them.
The decimated transform is an orthogonal basis, so it has exactly as many coefficients as pixels. That economy has a price. A shift of the image by one pixel changes which samples each level keeps, so the coefficients change in more than position. Nason and Silverman described the stationary transform, which computes the transform for all shifts at once. It has 3 J + 1 coefficients per pixel instead of one. Coifman and Donoho traced some artifacts of wavelet denoising near edges to this missing shift invariance. Their answer, which they called cycle spinning, is to denoise every shifted copy and average the results. With a fixed threshold, the stationary transform does exactly this for all 2^J x 2^J shifts at once. The tests check the two against each other.
Kernel or operator¶
The Inspector asks the engine for the stages with the current settings. For the stationary transform, they are the analysis, the filter taps from PyWavelets, the noise estimate, the threshold rule, the shrink rule and the synthesis. For cycle spinning, the shifts and the average come first and last. The filter taps are those of wavelet thresholding.
Algorithm¶
- For the stationary transform, add rows and columns with the border mode until each side is a multiple of 2^J.
- Split the channel with the stationary transform into an approximation and J levels of details, each at full size.
- Estimate the noise sigma from the finest diagonal details, unless it is set.
- Choose a threshold for each detail subband with the threshold rule, and shrink every detail coefficient.
- Rebuild the channel with the inverse transform and remove the added rows and columns.
- For cycle spinning instead, threshold n^2 circularly shifted copies with the decimated transform, shift each back and average them.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Method transform |
Stationary transform | Stationary transform, Cycle spinning | The stationary transform skips the subsampling, so it covers every shift at once. Cycle spinning runs wavelet thresholding on shifted copies and averages them. |
Wavelet wavelet |
Symlet 4 (sym4) | Haar, Daubechies 2 (db2), Daubechies 4 (db4), Daubechies 8 (db8), Symlet 4 (sym4), Symlet 8 (sym8), Coiflet 1 (coif1), Coiflet 3 (coif3) | The orthogonal wavelet. Its filter taps come from PyWavelets. |
Levels levels |
3 | 1 to 5 | How many levels the transform has. It is capped at the deepest level the image size allows. |
Threshold rule rule |
BayesShrink | VisuShrink (universal), BayesShrink, SureShrink, Fixed threshold | How the threshold T is chosen, as in wavelet thresholding. The rules use the coefficients of the chosen transform. |
Shrink rule mode |
Soft | Soft, Hard | Soft thresholding sets small coefficients to 0 and moves the others toward 0 by T. Hard thresholding sets small coefficients to 0 and keeps the others. |
Noise sigma sigma |
0 | 0 to 100 | The standard deviation of the noise, in pixel values. 0 estimates it from the finest diagonal details. |
Threshold threshold |
20 | 0 to 255 | The threshold T in pixel values, for the fixed threshold rule only. |
Shifts shifts |
4 | 1 to 8 | For cycle spinning, the shifts in each direction, from 0 to this number minus 1. The filter runs once per pair of shifts, so 4 means 16 runs. |
Border mode border |
Reflect | 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, Color only | Which part of the color image the filter changes. |
Implementation¶
swt_denoise in engine/src/pixelnexus_engine/filters/wavelets.py runs stationary_plane or cycle_spin_plane on each channel the scope names. stationary_plane pads the plane with NumPy in the border mode and calls pywt.swt2 and pywt.iswt2. In between, it uses the noise estimate, threshold rules and shrink rules of wavelet thresholding. cycle_spin_plane shifts the plane with np.roll, runs wavelet_threshold_plane, shifts the result back and averages. There is no live preview. The result arrives when you click Apply.
Worked example¶
| Wavelet | Decimated | Cycle spinning, 2 | Cycle spinning, 4 | Stationary |
|---|---|---|---|---|
| haar | 29.57 | 31.64 | 31.87 | 31.89 |
| sym4 | 29.80 | 30.79 | 30.99 | 30.92 |
The PSNR in dB against the clean disks, for the disks with Gaussian noise of sigma 20, 22.66 dB before the filter. The image and the noise are those of the wavelet thresholding example. All columns use BayesShrink, soft thresholding, 3 levels and the estimated noise sigma. Decimated is wavelet thresholding. The stationary transform covers all 8 x 8 shifts of 3 levels. It raises the PSNR by 2.32 dB with Haar and by 1.12 dB with sym4. With 4 shifts, cycle spinning comes within 0.07 dB of it.
| Transform | Largest change |
|---|---|
| Decimated | 61.59 |
| Stationary | 0.00 |
The noisy image is moved in a circle by 3 rows and 5 columns, filtered, and compared with the filtered image moved the same way. The table shows the largest difference in pixel values, before rounding. Both use the Wrap border mode. The decimated transform gives a different result for the moved image. The stationary transform gives the same result, moved.
Complexity¶
- Time: \(O(N L J)\)
- Memory: \(O(N J)\)
N is the number of pixels, L the number of filter taps and J the number of levels. Each level of the stationary transform works on the whole image. Cycle spinning costs n^2 runs of wavelet thresholding, each O(N L).
Artifacts and limitations¶
Limitations
- Needs memory for 3 J + 1 subbands, each the size of the image, in 64-bit floats.
- The transform wraps around, so content near one edge can affect the other edge.
- The threshold rules assume independent coefficients. In the stationary transform, neighboring coefficients are correlated.
Artifacts
- Faint ringing along strong edges.
- With cycle spinning and few shifts, weaker versions of the blocky spots of the decimated transform.
Tests¶
The main reference is the definition of Coifman and Donoho, written out in the test with PyWavelets. Each of the 8 x 8 circular shifts is thresholded with the periodic decimated transform, shifted back and averaged. The stationary transform matches it to within 10^-9 for three wavelets and both shrink rules. Cycle spinning matches cycle_spin of scikit-image for 1, 2 and 3 shifts. More tests check that the stationary result moves with the image for every threshold rule, while the decimated one does not. They also check VisuShrink against a threshold computed by hand, and that odd sizes come back whole for every border mode.
References¶
- Nason, G. P., and Silverman, B. W. The stationary wavelet transform and some statistical applications. In Wavelets and Statistics, Lecture Notes in Statistics 103, 281 to 299. Springer, 1995. DOI 10.1007/978-1-4612-2544-7_17.
- Coifman, R. R., and Donoho, D. L. Translation-invariant de-noising. In Wavelets and Statistics, Lecture Notes in Statistics 103, 125 to 150. Springer, 1995. DOI 10.1007/978-1-4612-2544-7_9.
- Donoho, D. L., and Johnstone, I. M. Ideal spatial adaptation by wavelet shrinkage. Biometrika 81(3), 425 to 455, 1994. DOI 10.1093/biomet/81.3.425.
- Chang, S. G., Yu, B., and Vetterli, M. Adaptive wavelet thresholding for image denoising and compression. IEEE Transactions on Image Processing 9(9), 1532 to 1546, 2000. DOI 10.1109/83.862633.
- Lee, G. R., Gommers, R., Waselewski, F., Wohlfahrt, K., and O'Leary, A. PyWavelets. A Python package for wavelet analysis. Journal of Open Source Software 4(36), 1237, 2019. DOI 10.21105/joss.01237.