Contourlet filtering¶
| Fact | Value |
|---|---|
| Also called | Contourlet denoising, Contourlet transform, Pyramidal directional filter bank |
| Status | Implemented and tested |
| Family | Wavelet and multiscale filters |
| Engine | Science engine |
| Type | Nonlinear, transform, contourlet coefficient shrinkage |
| Output | Image |
| Operator shown as | transform (exact) |
| Support radius | global |
| Code | engine/src/pixelnexus_engine/filters/contourlet.py, contourlet |
| Operator code | engine/src/pixelnexus_engine/filters/contourlet.py, contourlet_representation |
| Packages | PyWavelets, SciPy |
| Channels | RGB, Brightness only |
Overview¶
Contourlet filtering removes noise while it keeps edges and lines in any direction. Wavelets split an image by size and into three directions only. A smooth edge then crosses many wavelet positions, and each needs its own large coefficient. Do and Vetterli built the contourlet transform to follow such contours with fewer coefficients. It splits the image by size with a Laplacian pyramid, then splits each size into many directions with a directional filter bank. An edge ends up in the few subbands that match its direction, while noise spreads over all of them. The filter sets the small coefficients to zero and puts the image back together. It runs in the PixelNexus engine on your computer.
How it works¶
- Blur and halve the image a few times. At each size, keep the detail the blur removed.
- Split each detail image into directional subbands.
- Estimate the noise level, and set the coefficients below the threshold of their subband to zero.
- Run the directional split backward, and add the details back size by size.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(c_j\): The coarse image at level j, c_0 is the channel
- \(d_j\): The band at level j, the detail the coarser level cannot predict
- \(h, g\): The 9-7 analysis and synthesis low-pass filters, 9 and 7 taps
- \(w_{j,k}\): The coefficients of directional subband k of band j
- \(\sigma\): The noise level of the channel
- \(s_{j,k}\): The noise gain of subband k of band j
- \(\kappa\): The threshold factor
- \(\eta_T\): The shrink rule with threshold T
The image channel is c_0. The Laplacian pyramid of Burt and Adelson makes a coarse image c_j+1 with the low-pass filter h. It keeps the difference d_j to its prediction with the filter g. The filters h and g are the biorthogonal 9-7 filters. The directional filter bank, DFB, splits each band d_j into K subbands w_j,k, each holding edges in one wedge of directions. It is a tree of two-channel quincunx filter banks. Each bank is a ladder of two steps with the filter B, so it rebuilds exactly whatever B is. The noise level of the image is sigma. The noise gain s_j,k is the standard deviation that white noise of level 1 has in subband k of band j. The shrink rule eta is the one of wavelet thresholding. The coarse image c_J is kept. With kappa 0 every step is undone exactly.
The Laplacian pyramid of Burt and Adelson keeps, at each level, the difference between an image and its prediction from the next coarser level. Here the low-pass filters are the biorthogonal 9-7 filters of Cohen, Daubechies and Feauveau, as Do and Vetterli use them. Adding the prediction back undoes each level exactly, whatever the filters are.
The directional filter bank of Bamberger and Smith splits the frequency plane into wedges. Do and Vetterli build it as a tree of two-channel filter banks with quincunx sampling, which keeps every second pixel in a checkerboard pattern. The first bank splits the directions into edges closer to horizontal and edges closer to vertical. The second level splits each half again at 45 degrees. From the third level on, a shear in front of each bank turns its two fan-shaped halves into narrower wedges. With l levels, there are 2^l wedges. They have equal widths in slope, not in angle.
Each two-channel bank is a ladder, also called a lifting structure. With a0 the pixels of the even checkerboard and a1 the odd ones, it runs two steps:
where:
- \(a_0\) and \(a_1\) are the pixels of the two checkerboard cosets.
- \(B\) is a filter that predicts one coset from its neighbors in the other.
This is an exact computation. Running the two steps backward with the same B rebuilds a0 and a1, whatever B is. B is the filter of Phoong, Kim, Vaidyanathan and Ansari. They design it from one 1-D filter beta, applied along both diagonals of the checkerboard. PixelNexus multiplies B by (-1) to the row index, which turns its diamond-shaped pass band into a fan. The filter beta has 12 taps, the six values of their Example 3.2, mirrored. The toolbox of Do and Vetterli calls this filter "pkva".
The transform is not orthogonal, and the pyramid makes 4/3 as many coefficients as pixels. So white noise has a different strength in each subband. The filter measures that strength once, on white noise with a fixed seed, and scales each threshold by it.
Kernel or operator¶
The Inspector shows the stages with the current settings. The pyramid stage lists its 9 and 7 filter taps. The directional filter bank stage lists the six ladder values. Then come the threshold, the shrink rule and the rebuild.
Algorithm¶
- Extend the channel symmetrically to a size the transform can halve often enough.
- Build the Laplacian pyramid with the 9-7 filters, J levels.
- Split each band into K directional subbands with the tree of ladder filter banks.
- Estimate the noise level of the channel, or take the given one.
- Shrink each subband with kappa times the noise level times its noise gain.
- Run the filter banks backward, add the bands back to the predictions, and crop.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Levels levels |
3 | 1 to 5 | How many times the Laplacian pyramid halves the image. Each level gives one band, split into directions. |
Directions directions |
8 | 4, 8, 16 | How many directional subbands each band has, over 180 degrees. The directional tree has 2, 3 or 4 levels. |
Threshold factor factor |
3 | 0 to 8 | The threshold is this factor times the noise level in each subband. 0 keeps every coefficient, and the image comes back unchanged. |
Shrink rule mode |
Hard | Hard, Soft | Hard thresholding sets small coefficients to 0 and keeps the others. Soft thresholding also moves the others toward 0 by T. |
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. |
Channels channelScope |
RGB | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
contourlet in engine/src/pixelnexus_engine/filters/contourlet.py runs contourlet_plane on each channel the scope names. The 9-7 taps come from PyWavelets' bior4.4 wavelet. The ladder values are copied from the paper of Phoong and his coauthors, and a test checks them. The functions lp_dec and lp_rec run the pyramid with scipy.ndimage.correlate1d. The functions dfb_dec and dfb_rec run the tree of ladder banks, with each filter applied by FFT on the whole band. The shrink rules come from wavelet thresholding, and the noise estimate from the curvelet-inspired filter.
Some choices are PixelNexus's own, not from the paper. Each subband stays on the grid of its band, with zeros off its sampling lattice, so no resampling to rectangles is needed. The function plan picks the shear of each bank from the geometry of its wedge. The image is extended symmetrically, and the directional filter bank wraps around that extension. There is no live preview. The result arrives when you click Apply.
Worked example¶
| Image | Noisy | 4 directions | 8 | 16 | 8, soft | Wavelet |
|---|---|---|---|---|---|---|
| Lines | 22.18 | 25.84 | 25.78 | 25.64 | 24.81 | 27.12 |
| Disks | 22.66 | 28.48 | 27.80 | 26.60 | 26.44 | 29.80 |
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. The contourlet columns use 3 levels, a threshold factor of 3 and hard thresholding, except the soft column. Wavelet is wavelet thresholding with its defaults. With the factor set to 0, the noisy lines come back with 0 changed pixels. In the figure, the wedge around 166 degrees keeps the line at about 163 degrees and little of the other two.
On these two test images, wavelet thresholding with BayesShrink does better. The images are made of flat areas and a few edges, which wavelets handle well. The fourth panel of the figure shows what the directional split adds: one wedge alone holds the shallow line, and the two steep lines are almost gone.
Complexity¶
- Time: \(O(K N log N)\)
- Memory: \(O(K N)\)
N is the number of pixels and K the number of directions. The directional tree has K - 1 banks for each band, and each bank runs two FFT filters on the full band. Each subband is kept on the grid of its band, with zeros off its lattice. The bands shrink by 4 per level, so the finest band costs the most.
Artifacts and limitations¶
Limitations
- The pyramid makes 4/3 as many coefficients as pixels, and the transform is not orthogonal, so the noise in the subbands is correlated.
- On images made of flat areas and few edges, wavelet thresholding with BayesShrink often does better.
- The published pkva filter values have three significant digits, so B passes 0.978 of a constant instead of 1. This leaks a little of the smooth part into the high-pass branch of each bank. The rebuild stays exact.
Artifacts
- Short thin streaks in flat areas, where a noise coefficient passes the threshold. Each looks like a piece of line in the direction of its subband.
- Faint ripples along strong lines and edges with hard thresholding.
Tests¶
The tests check what follows from the definitions. The ladder values are the published ones, and each tap joins the two checkerboard cosets. The pyramid, the directional filter bank with 1 to 4 levels and the whole transform with 4, 8 and 16 directions rebuild random images to within 10^-9. Without thresholding, the filter returns the image unchanged. Each subband holds 1 / 2^l of the points, and the subbands do not overlap. A wave in the middle of each of the 8 wedges puts over 80 percent of its energy in that wedge. A line at 37 degrees lands in the subband whose wedge is centered at 36.9 degrees. The measured noise strengths agree with fresh noise to within 10 percent. On a noisy disk with a line, the PSNR rises by more than 3 dB, and the disk edge stays sharp.
References¶
- Do, M. N., and Vetterli, M. The contourlet transform. An efficient directional multiresolution image representation. IEEE Transactions on Image Processing 14(12), 2091 to 2106, 2005. DOI 10.1109/TIP.2005.859376.
- Phoong, S.-M., Kim, C. W., Vaidyanathan, P. P., and Ansari, R. A new class of two-channel biorthogonal filter banks and wavelet bases. IEEE Transactions on Signal Processing 43(3), 649 to 665, 1995. DOI 10.1109/78.370620.
- Bamberger, R. H., and Smith, M. J. T. A filter bank for the directional decomposition of images. Theory and design. IEEE Transactions on Signal Processing 40(4), 882 to 893, 1992. DOI 10.1109/78.127960.
- Burt, P. J., and Adelson, E. H. The Laplacian pyramid as a compact image code. IEEE Transactions on Communications 31(4), 532 to 540, 1983. DOI 10.1109/TCOM.1983.1095851.
- Cohen, A., Daubechies, I., and Feauveau, J.-C. Biorthogonal bases of compactly supported wavelets. Communications on Pure and Applied Mathematics 45(5), 485 to 560, 1992. DOI 10.1002/cpa.3160450502.