hyperspy.misc.tv_denoise module

hyperspy.misc.tv_denoise.tv_denoise(im, weight=50, eps=0.0002, keep_type=False, n_iter_max=200)

Perform total-variation denoising on 2-d and 3-d images

Parameters
  • im (ndarray (2d or 3d) of ints, uints or floats) – input data to be denoised. im can be of any numeric type, but it is cast into an ndarray of floats for the computation of the denoised image.

  • weight (float, optional) – denoising weight. The greater weight, the more denoising (at the expense of fidelity to input)

  • eps (float, optional) –

    relative difference of the value of the cost function that determines the stop criterion. The algorithm stops when:

    (E_(n-1) - E_n) < eps * E_0

  • keep_type (bool, optional (False)) – whether the output has the same dtype as the input array. keep_type is False by default, and the dtype of the output is np.float

  • n_iter_max (int, optional) – maximal number of iterations used for the optimization.

Returns

out – denoised array

Return type

ndarray

Notes

The principle of total variation denoising is explained in http://en.wikipedia.org/wiki/Total_variation_denoising

The principle of total variation denoising is to minimize the total variation of the image, which can be roughly described as the integral of the norm of the image gradient. Total variation denoising tends to produce “cartoon-like” images, that is, piecewise-constant images.

This code is an implementation of the algorithm of Rudin, Fatemi and Osher that was proposed by Chambolle in 1.

References

1

A. Chambolle, An algorithm for total variation minimization and applications, Journal of Mathematical Imaging and Vision, Springer, 2004, 20, 89-97.

Examples

>>> # 2D example using ascent
>>> import scipy
>>> ascent = scipy.misc.ascent().astype(np.float)
>>> ascent += 0.5 * ascent.std()*np.random.randn(*ascent.shape)
>>> denoised_ascent = tv_denoise(ascent, weight=60)
>>> # 3D example on synthetic data
>>> x, y, z = np.ogrid[0:40, 0:40, 0:40]
>>> mask = (x -22)**2 + (y - 20)**2 + (z - 17)**2 < 8**2
>>> mask = mask.astype(np.float)
>>> mask += 0.2*np.random.randn(*mask.shape)
>>> res = tv_denoise_3d(mask, weight=100)