Curvelet-inspired directional filter¶
| Fact | Value |
|---|---|
| Also called | Curvelet-inspired denoising, Polar wedge filter, Directional frequency tiling |
| Status | Implemented and tested |
| Family | Frequency-domain filters |
| Engine | Science engine |
| Type | Nonlinear, frequency, directional tile thresholding |
| Output | Image |
| Operator shown as | transform (exact) |
| Support radius | global |
| Code | engine/src/pixelnexus_engine/filters/directional.py, directional_curvelet |
| Operator code | engine/src/pixelnexus_engine/filters/directional.py, directional_representation |
| Packages | SciPy, PyWavelets |
| Channels | Brightness only, RGB |
Overview¶
The curvelet-inspired filter splits the spectrum of the image into smooth wedges, one for each band of sizes and each range of directions, as the curvelet transform does. In each wedge it keeps the strong parts, which belong to lines and edges, and drops the weak ones, which are mostly noise. Or it keeps only the wedges of one direction. It borrows the curvelet tiling but not the curvelet transform itself, so it is called curvelet-inspired. The filter runs in the PixelNexus engine on your computer.
How it works¶
- Extend the channel with the border mode and take its FFT.
- Cut the spectrum into smooth tiles: octave bands of frequency, each cut into wedges by angle, with more wedges at finer scales.
- To remove noise, turn each tile back into an image, set its weak values to zero, and put all tiles back together.
- To keep one direction, keep only the tiles near that direction, and the coarse tile if you ask for it.
- Cut the result back to the image.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(f, |f|, \theta(f)\): A frequency in cycles per pixel, its distance from 0 and its angle modulo pi
- \(W_j\): The radial window of band j. Band 0 is the finest.
- \(V\): The angular window, with Meyer's polynomial nu
- \(L_j\): The number of wedges in band j
- \(c_{j,l}\): The coefficients of tile j l
- \(\eta\): Hard thresholding at k sigma times the RMS of the mask
The tiles follow the frequency tiling of the curvelet transform of Candes, Demanet, Donoho and Ying. It has octave bands in radius, each cut into wedges by angle, with more wedges at finer scales. Here the radial windows are W_j^2 = Phi_(j-1)^2 - Phi_j^2. Phi_j is 1 up to a radius of 0.125 / 2^j cycles per pixel and falls smoothly to 0 at twice that radius. The finest band is 1 - Phi_0^2 and the coarse low-pass tile is Phi_(S-1)^2. These squares add up to 1. In each band, L_j wedges are centered at the angles pi l / L_j. V uses Meyer's polynomial nu, so the squares of neighboring wedges also add up to 1. Here theta is the angle of the frequency, modulo pi. L_j halves every second scale toward the coarse end. To remove noise, each tile is filtered, and coefficients below the factor k times sigma times the RMS of the mask are set to 0. That is the standard deviation that white noise of sigma has in the tile. Filtering once more with the mask and adding all tiles rebuilds the image. The tiles are not the curvelets of a curvelet transform, which come with their own sampling and a fast algorithm, so this is a curvelet-inspired filter.
Wavelets describe points well but edges poorly, since an edge crosses many wavelet positions. Curvelets, after Candes, Demanet, Donoho and Ying, are needle-shaped elements at many scales and directions. Their width is about the square of their length, which is why the number of directions doubles every second scale. A smooth edge then needs far fewer coefficients. The tiles here follow the frequency tiling of the curvelet transform: octave bands in radius and wedges in angle. The windows use Meyer's polynomial nu from the theory of the Meyer wavelet, which makes every transition smooth.
The masks form what is called a tight frame. Their squares add up to 1 at every frequency, so filtering with each mask twice, once to get the tile and once to put it back, returns the image exactly. Thresholding then works as in wavelet thresholding. For white noise of standard deviation sigma, Parseval's theorem gives the noise of tile t as sigma times the root mean square of its mask. Coefficients below k times that value are set to zero. Long lines and edges fall into few tiles, with large values, so they survive. Noise spreads evenly over all tiles and is removed.
Kernel or operator¶
To remove noise, the Inspector asks the engine for the stages with the current settings: the spectrum, the tiles, the tile coefficients, the threshold and the synthesis. To keep one direction, it shows the response, the sum of the squared masks of the kept tiles, as a picture of the spectrum and a profile.
Algorithm¶
- Extend the channel with the border mode and take its FFT.
- Build the tiles, smooth masks whose squares add up to 1 at every frequency.
- To keep one direction, multiply the spectrum by the sum of the squared masks of the kept tiles and transform back.
- To remove noise, for each tile multiply the spectrum by its mask and transform back to get its coefficients.
- Set the coefficients below the factor times the noise of the tile to 0. Keep the coarse low-pass tile as it is.
- Transform each tile back, multiply by its mask again, add all tiles and transform back.
- Cut the result back to the image.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Mode mode |
Remove noise | Remove noise, Keep one direction | Remove noise sets the small coefficients of every tile to 0. Keep one direction keeps only the tiles near one orientation. |
Scales scales |
3 | 2 to 5 | How many bands of directional tiles, each an octave of frequency. A coarse low-pass tile covers the rest. |
Directions directions |
16 | 8, 16, 32 | The number of directions at the finest scale, over 180 degrees. It halves every second scale toward the coarse end, down to 4. |
Threshold factor factor |
3 | 0 to 8 | For removing noise, the threshold is this factor times the noise in each tile. 0 keeps every coefficient. |
Noise sigma sigma |
0 | 0 to 100 | The standard deviation of the noise, in pixel values. 0 estimates it from the finest diagonal wavelet details. |
Line angle direction |
0 | 0 to 180 deg | For keeping one direction, the angle of the lines to keep, counterclockwise on screen. 0 keeps horizontal lines. |
Angle range width |
15 | 1 to 90 deg | For keeping one direction, the tiles whose orientation is within this many degrees of the line angle are kept. |
Keep coarse part keepCoarse |
on | On or off | For keeping one direction, also keep the coarse low-pass tile, which has no direction. |
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 |
Brightness only | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
directional_curvelet in engine/src/pixelnexus_engine/filters/directional.py runs directional_plane on each channel the scope names. curvelet_tiles builds the masks on the half spectrum of scipy.fft.rfft2. It uses the radial bands of radial_bands and the angular windows of angular_windows. symmetric_nyquist makes the masks agree at opposite frequencies on the last column, so the results stay real. The noise of each tile comes from tile_rms. Without the coarse part, the kept detail is shown around a mid gray of 128. There is no live preview. The result arrives when you click Apply.
Worked example¶
| Image | Noisy | Factor 2 | Factor 3 | Factor 4 | Wavelet | Stationary |
|---|---|---|---|---|---|---|
| Lines | 22.18 | 28.70 | 29.88 | 29.04 | 27.12 | 28.24 |
| Disks | 22.66 | 29.03 | 30.79 | 29.70 | 29.80 | 30.92 |
The PSNR in dB against the clean image, for Gaussian noise of sigma 20 from NumPy's default_rng with seed 7. Both images are 160 by 160 pixels. The lines image has three straight lines, 3 pixels wide. Factor 2 to 4 is the threshold factor of this filter, with its other defaults. Wavelet is wavelet thresholding and Stationary is stationary wavelet filtering, both with their defaults. With the defaults there are 16, 16, 8 directional tiles from the finest scale to the coarsest, plus the low-pass tile.
Complexity¶
- Time: \(O(T N log N)\)
- Memory: \(O(N)\)
N is the number of pixels of the extended image and T the number of tiles. Removing noise needs two FFTs per tile. Keeping one direction needs one FFT each way.
Artifacts and limitations¶
Limitations
- Not a curvelet transform. The tiles borrow the curvelet tiling, but the coefficients are full-size images, one per tile, without the sampling of a real curvelet transform.
- The noise level of each tile assumes white noise of the same strength everywhere.
- Slower than wavelet thresholding, since every tile needs its own FFTs.
Artifacts
- Faint directional streaks where noise lines up by chance with a tile.
- Ringing along edges at angles between two tiles, where both tiles are thresholded apart.
Tests¶
The tests check that Meyer's polynomial satisfies nu(x) + nu(1 - x) = 1. The squares of the masks must add up to 1 to within 10^-12, for 2 and 4 scales, 8 and 32 directions, and even and odd sizes. With a threshold factor of 0, the image comes back to within 10^-9 for three border modes. Stripes at 0, 45, 90 and 135 degrees are kept when the line angle matches and removed when it is 90 degrees off. The noise of the tile coefficients of white noise matches sigma times the RMS of the mask. Removing noise from lines raises the PSNR by more than 5 dB. The engine API tests run jobs and check both kinds of representation.
References¶
- Candes, E. J., Demanet, L., Donoho, D. L., and Ying, L. Fast discrete curvelet transforms. Multiscale Modeling and Simulation 5(3), 861 to 899, 2006. DOI 10.1137/05064182X.
- Starck, J.-L., Candes, E. J., and Donoho, D. L. The curvelet transform for image denoising. IEEE Transactions on Image Processing 11(6), 670 to 684, 2002. DOI 10.1109/TIP.2002.1014998.
- Daubechies, I. Ten Lectures on Wavelets. SIAM, 1992. Meyer's auxiliary polynomial nu. DOI 10.1137/1.9781611970104.