# Running the BM3D Denoising Algorithm in Python

I am looking for a strong baseline in image denoising and therefore wanted to have the BM3D algorithm in my benchmark.

These 2 python implementations:

have been unmaintained for a long time (and the second one is documented in what I think is chinese). I have experimented a bit with the first one without satisfactory results (see https://github.com/ericmjonas/pybm3d/issues/11 with non satisfactory fixes like clipping).

This package : https://pypi.org/project/bm3d/#description , doesn't have a documentation or source code easily findable.

Then I found this: https://docs.opencv.org/master/de/daa/group__xphoto.html#ga2fc5a9661c1338a823fb3290673a880d, in the docs of opencv but there is no indication as to how to use it and no examples in python. I saw this SO question but it's for a C++ implementation and I don't know how it would translate in Python because I am not familiar at all with opencv.

• Have you found something? Nov 26 '19 at 11:54
• @David see the answer below Nov 26 '19 at 13:08

What I resorted to was using the PyPI package, which is advertised here: http://www.cs.tut.fi/~foi/GCF-BM3D/index.html#ref_software.

I dug a bit in the source code, and found that I could perform BM3D, in the following fashion:

import bm3d

denoised_image = bm3d.bm3d(image_noisy, sigma_psd=30/255, stage_arg=bm3d.BM3DStages.HARD_THRESHOLDING)


I installed bm3d using pip (pip install bm3d) and needed OpenBlas (sudo apt-get install libopenblas-dev).

• While this solution works, it doesn't implement the full bm3d algorithm, which is more powerful when used with stage_arg=bm3d.BM3DStages.ALL_STAGES. It is however twice slower with all stages. Nov 26 '19 at 16:45
• Just as a confirmation, this method allows me to reproduce the results of arxiv.org/pdf/1902.02452.pdf (Table 1) and arxiv.org/pdf/1608.03981.pdf (Table 2) on the BSD68 dataset in terms of PSNR. Nov 27 '19 at 21:07
• You can find an example of how I implemented it in those lines: github.com/zaccharieramzi/understanding-unets/blob/master/… Jun 29 '21 at 14:43

If you don't want to use the PyPI package for bm3d, you can use ffmpeg and run the bm3d filter as an OS command-

command="ffmpeg -i "+input_image_path+" -filter_complex bm3d=sigma=30/255:block=4:bstep=2:group=1:hdthr=10000:estim=basic /path/to/output/directory/output.png"
os.system(command)


This takes lesser computation time.