Skip to content

ericmjonas/pybm3d

Repository files navigation

PyBM3D

License: GPL v3 Travis-CI Status Scrutinizer Code Quality

So you want to denoise some images, or maybe shrink inside a projected gradient algorithm?

This Python package provides an interface for the BM3D denoising strategy which is based on enhanced sparse representations in the transform-domain. The enhancement of the sparsity is achieved by grouping similar 2D image fragments (e.g. blocks) into 3D data arrays. Visit the offical BM3D website for a detailed explanation, benchmark results and other related works.

The core C implementation of BM3D is based on the work of Marc Lebrun.

Installation

PyBM3D is supported for Linux and OSX and Python 2.7 and 3.6. Please follow the installation instructions:

  1. FFTW3:
    1. Linux: sudo apt-get install libfftw3-dev
    2. OSX: brew update && brew install fftw
  2. pip install pybm3d

Example

Denoising a RGB color image
import numpy as np
import skimage.data
from skimage.measure import compare_psnr

import pybm3d


noise_std_dev = 40
img = skimage.data.astronaut()
noise = np.random.normal(scale=noise_std_dev,
                         size=img.shape).astype(img.dtype)

noisy_img = img + noise

out = pybm3d.bm3d.bm3d(noisy_img, noise_std_dev)

noise_psnr = compare_psnr(img, noisy_img)
out_psnr = compare_psnr(img, out)

print("PSNR of noisy image: ", noise_psnr)
print("PSNR of reconstructed image: ", out_psnr)

License

This project is released under the terms of the GPL3 license.