Skip to content

BM3D-inspired denoising

Fact Value
Also called BM3D lite, Simplified BM3D, Block-matching and 3D filtering
Status Implemented and tested
Family Nonlinear spatial filters
Engine Science engine
Type Nonlinear, transform, collaborative filtering
Output Image
Operator shown as algorithm (simplified)
Support radius search radius + 7
Code engine/src/pixelnexus_engine/filters/bm3d_lite.py, bm3d_lite
Operator code engine/src/pixelnexus_engine/filters/bm3d_lite.py, bm3d_lite_representation
Packages SciPy, scikit-image

Overview

BM3D, by Dabov, Foi, Katkovnik and Egiazarian, is one of the strongest classical denoisers. This filter is a simplified version in PixelNexus's own code. The full BM3D package is left out because its license is unclear. For each small patch, the filter gathers similar patches from nearby and stacks them into a 3D group. Because the patches share their real content, the noise can be removed from the whole stack at once. A first step uses a hard threshold. A second step uses a Wiener filter, guided by the result of the first. The filter runs in the PixelNexus engine.

Four panels. The clean image has dark and gray vertical stripes on the left half and a light flat area with a lighter disk on the right. The noisy image is covered in grain. The basic estimate shows sharp stripes and a clean disk with faint grain left in the flat area. The final estimate looks the same, with the flat area slightly smoother. Four panels. The clean image has dark and gray vertical stripes on the left half and a light flat area with a lighter disk on the right. The noisy image is covered in grain. The basic estimate shows sharp stripes and a clean disk with faint grain left in the flat area. The final estimate looks the same, with the flat area slightly smoother.
Stripes 3 pixels wide beside a flat area with a disk, then with noise of sigma 20. Then the basic estimate of the first step and the final estimate, with sigma set to 20.

How it works

  1. For reference patches of 8 x 8 every 3 pixels, find up to 16 similar patches in the search window.
  2. Stack them, take the 3D DCT, set small coefficients to 0, and transform back.
  3. Average all patch estimates into the basic estimate, weighting groups by how few coefficients they kept.
  4. Match again on the basic estimate, up to 32 patches, and stack the noisy and the basic patches.
  5. Scale the noisy group by the Wiener coefficients from the basic group, and transform back.
  6. Average all patch estimates into the final estimate.

Mathematical foundation

\[ \hat{P}^{\text{hard}} = T_{3D}^{-1}\!\left(\gamma(T_{3D}(\mathbf{P}))\right), \qquad \hat{P}^{\text{wien}} = T_{3D}^{-1}\!\left(\omega \cdot T_{3D}(\mathbf{P})\right), \quad \omega = \frac{\lvert T_{3D}(\mathbf{B}) \rvert^2}{\lvert T_{3D}(\mathbf{B}) \rvert^2 + \sigma^2} \]

The formula shows the default parameter values.

where

  • \(\mathbf{P}\): A 3D group of similar noisy patches
  • \(\mathbf{B}\): The same group from the basic estimate
  • \(T_{3D}\): The orthonormal 3D DCT
  • \(\gamma\): The hard threshold at 2.7 sigma
  • \(\omega\): The empirical Wiener coefficients
  • \(\sigma\): The noise standard deviation

P is a 3D group: patches of 8 x 8 pixels similar to a reference patch, stacked. T_3D is the orthonormal 3D DCT. In the first step, gamma sets every coefficient with |x| <= 2.7 sigma to 0. Similar patches share their structure, so the stack's signal gathers in a few large coefficients while the noise spreads over all of them. In the second step, B is the same group taken from the basic estimate, and omega is an empirical Wiener filter. Every patch estimate is put back in place and averaged with a weight that favors groups with less left after filtering.

Similar patches make a group with strong correlation in all three directions. In a 3D transform, its signal gathers in a few large coefficients, while white noise spreads evenly over all of them. Setting small coefficients to 0 then removes most of the noise and keeps most of the signal. Each pixel lies in many patches, and many groups, so it gets many estimates. They are averaged with weights that favor groups with fewer coefficients left, since those are more reliable.

The second step uses the basic estimate as a guide. Matching on it is more reliable than on the noisy image. Its transform also tells how much signal each coefficient holds, which sets the Wiener factor omega for the same coefficient of the noisy group.

Kernel or operator

The filter has no kernel. Each group gets its own filtering in the transform domain. The Inspector asks the engine for the stages with the current settings.

Parameters

Parameter Default Values Meaning
Noise sigma sigma 0 0 to 100 levels The standard deviation of the noise. 0 estimates it with scikit-image's estimate_sigma, our choice.
Output output Final (after Wiener) Final (after Wiener), Basic (after hard threshold) The final estimate, or the basic estimate of the first step.
Search radius searchRadius 19 4 to 19 px Similar patches are searched in a window of 2 radius + 1 pixels. 19 gives the 39 x 39 window of Lebrun's study.
Channels channelScope RGB RGB, Each channel separately, Brightness only, Color only Which part of the color image the filter changes.

Implementation

bm3d_lite in engine/src/pixelnexus_engine/filters/bm3d_lite.py follows the step-by-step description of Lebrun's IPOL analysis. It uses the values of his parameter table. Patches are 8 x 8 with a step of 3, and groups hold up to 16 and 32 patches. The threshold is 2.7 sigma. The matching thresholds are 2500 and 400, or 5000 and 3500 above sigma 40. The reference patch always leads its group. Several parts are simpler than the full method, our choices:

  • Every transform is the orthonormal DCT, in 2D within the patches and in 1D across them. Lebrun's tables use this variant.
  • There is no Kaiser window in the aggregation. Lebrun found it does not raise the PSNR.
  • The 2D pre-threshold of the matching above sigma 40 is left out.
  • Each channel is processed on its own, not in the paper's opponent color space.

Worked example

Noise sigma Noisy PSNR (dB) Basic PSNR (dB) Final PSNR (dB) Estimated sigma Final PSNR with the estimate (dB)
10 28.19 44.47 44.45 9.8 44.53
20 22.20 39.67 39.67 19.6 39.68
30 18.80 37.00 36.75 29.1 36.76
50 14.77 32.94 32.59 46.1 32.61

The clean image of the figure, 160 x 160, with Gaussian noise rounded and clipped to 8 bits. The default search window of 39 x 39.

The first step does most of the work. It raises the PSNR by 16 to 18 dB. On this simple scene the second step adds nothing at sigma 10 and 20, and it loses about 0.3 dB at sigma 30 and 50. The stripes and the flat area are already almost perfect after the first step. On a scene with fine texture of a few levels, the second step helped, by 0.4 to 3.2 dB. The estimated sigma stays within 1 level of the truth up to sigma 30. With the estimate, the result is within 0.1 dB of the result with the true value.

Complexity

  • Time: \(O(N R^2)\)
  • Memory: \(O(N)\)

N is the number of pixels and R the side of the search window. The code loops over the reference patches in Python, so it is slow on large images.

Artifacts and limitations

Limitations

  • Simplified, so it falls short of the full BM3D, which uses other transforms, a Kaiser window and an opponent color space.
  • Slow in Python on large images.
  • Assumes white Gaussian noise of one known level.

Artifacts

  • Faint blocky patterns in flat areas at high noise.
  • Smoothed fine texture when sigma is set too high.

Tests

The matching thresholds must follow Lebrun's table, and the grid must step by 3 and end at the last patch. The matching must keep the closest patches within the threshold, with the reference first. Near the image border, the search window must be cut. A flat image must stay flat, apart from the small shrink of the Wiener factor, and a tiny sigma must leave the image. At sigma 10 and 30 the first step must gain at least 6 dB and the second must gain more. A sigma of 0 must estimate the noise near its true value. The outputs and the representation are checked too.

References

  • Dabov, K., Foi, A., Katkovnik, V., and Egiazarian, K. Image denoising by sparse 3-D transform-domain collaborative filtering. IEEE Transactions on Image Processing 16(8), 2080 to 2095, 2007. DOI 10.1109/TIP.2007.901238.
  • Lebrun, M. An analysis and implementation of the BM3D image denoising method. Image Processing On Line 2, 175 to 213, 2012. DOI 10.5201/ipol.2012.l-bm3d.