Skip to content

Shearlet-inspired directional filter

Fact Value
Also called Shearlet-inspired denoising, Sheared frequency filter, Cone-adapted 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_shearlet
Operator code engine/src/pixelnexus_engine/filters/directional.py, directional_representation
Packages SciPy, PyWavelets
Channels Brightness only, RGB

Overview

The shearlet-inspired filter splits the spectrum of the image into smooth sheared tiles, in a horizontal and a vertical cone of directions, as cone-adapted shearlets do. In each tile 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 tiles of one direction. It borrows the shearlet tiling but not the shearlet transform itself, so it is called shearlet-inspired. The filter runs in the PixelNexus engine on your computer.

Four panels: three thin bright lines crossing on a dark ground with strong grainy noise; the shearlet-inspired result, with clean lines and faint streaks along their directions; wavelet thresholding, with clean lines and a little blotchy grain; and only the diagonal line that falls from top left to bottom right, bright on a mid gray ground. Four panels: three thin bright lines crossing on a dark ground with strong grainy noise; the shearlet-inspired result, with clean lines and faint streaks along their directions; wavelet thresholding, with clean lines and a little blotchy grain; and only the diagonal line that falls from top left to bottom right, bright on a mid gray ground.
Three lines with Gaussian noise of sigma 20, the shearlet-inspired filter with the defaults, and wavelet thresholding. The last panel keeps only the direction of the 135 degree line.

How it works

  1. Extend the channel with the border mode and take its FFT.
  2. Cut the spectrum into smooth tiles: octave bands of frequency, each cut by slope into sheared tiles, in a horizontal and a vertical cone.
  3. To remove noise, turn each tile back into an image, set its weak values to zero, and put all tiles back together.
  4. To keep one direction, keep only the tiles near that direction, and the coarse tile if you ask for it.
  5. Cut the result back to the image.

Mathematical foundation

\[ W_{j,k}(f) = W_j(|f|)\, V\!\left(K_j\, \frac{f_y}{f_x} - k\right), \quad |f_y| \le |f_x|,\ k = -K_j \ldots K_j, \qquad c_{j,k} = \mathcal{F}^{-1}\big(W_{j,k}\, \mathcal{F} I\big), \qquad \hat{I} = \mathcal{F}^{-1}\Big(W_{\text{low}}^2\, \mathcal{F} I + \sum_{j,k} W_{j,k}\, \mathcal{F}\big(\eta(c_{j,k})\big)\Big), \qquad 4 K_0 = \text{16} \]

The formula shows the default parameter values.

where

  • \(f_x, f_y\): A frequency in cycles per pixel, with f_y growing downward
  • \(W_j\): The radial window of band j. Band 0 is the finest.
  • \(V\): The slope window, with Meyer's polynomial nu
  • \(K_j\): The number of shears on each side of the cone axis in band j
  • \(c_{j,k}\): The coefficients of tile j k
  • \(\eta\): Hard thresholding at k sigma times the RMS of the mask

Cone-adapted shearlets, after Guo and Labate, split the spectrum into a horizontal cone, where |f_y| <= |f_x|, and a vertical cone. In each cone, the directions are set by shearing. The slope f_y / f_x, or f_x / f_y in the vertical cone, is cut into windows centered at k / K_j. So the directions are evenly spaced in slope, not in angle. Here the radial windows W_j are those of the curvelet-inspired filter, with squares that add up to 1. V uses Meyer's polynomial nu, so the squares of neighboring slope windows add up to 1 too. The tiles of the two cones that meet at a diagonal are joined into one, which gives 4 K_j tiles per band. K_j halves every second scale toward the coarse end. Noise removal and orientation work as in the curvelet-inspired filter. The tiles are not shearlets of a shearlet transform, which come with their own sampling and generating functions, so this is a shearlet-inspired filter.

Shearlets, after Guo and Labate, reach the same goal as curvelets with a different tool. Instead of rotating, they shear: a tile is moved along the slope f_y / f_x, which keeps every operation on the square grid of the image. A cone-adapted system uses one cone for the mostly horizontal frequencies and one for the mostly vertical ones, so the slope never grows past 1. The directions are evenly spaced in slope, not in angle, so they lie closer together near the axes. Here the tiles of the two cones that meet at a diagonal are joined, so that no tile has an edge there. The windows use Meyer's polynomial nu, 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

  1. Extend the channel with the border mode and take its FFT.
  2. Build the tiles, smooth masks whose squares add up to 1 at every frequency.
  3. To keep one direction, multiply the spectrum by the sum of the squared masks of the kept tiles and transform back.
  4. To remove noise, for each tile multiply the spectrum by its mask and transform back to get its coefficients.
  5. Set the coefficients below the factor times the noise of the tile to 0. Keep the coarse low-pass tile as it is.
  6. Transform each tile back, multiply by its mask again, add all tiles and transform back.
  7. 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_shearlet in engine/src/pixelnexus_engine/filters/directional.py runs directional_plane on each channel the scope names. shearlet_tiles builds the masks on the half spectrum of scipy.fft.rfft2. It uses the radial bands of radial_bands and the slope windows of slope_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.68 29.88 29.06 27.12 28.24
Disks 22.66 29.01 30.76 29.68 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 shearlet transform. The tiles borrow the cone-adapted shearlet tiling, but the coefficients are full-size images, one per tile, without the sampling of a real shearlet transform.
  • The directions are even in slope, so they are closer together near the cone axes than near the diagonals.
  • 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

  • Guo, K., and Labate, D. Optimally sparse multidimensional representation using shearlets. SIAM Journal on Mathematical Analysis 39(1), 298 to 318, 2007. DOI 10.1137/060649781.
  • Kutyniok, G., and Labate, D. Introduction to shearlets. In Shearlets. Multiscale Analysis for Multivariate Data, 1 to 38. Birkhauser, 2012. DOI 10.1007/978-0-8176-8316-0_1.
  • Daubechies, I. Ten Lectures on Wavelets. SIAM, 1992. Meyer's auxiliary polynomial nu. DOI 10.1137/1.9781611970104.