hyperspy.misc.tv_denoise module

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

Perform total-variation denoising

Parameters
  • im (ndarray) – input data to be denoised

  • 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 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 https://en.wikipedia.org/wiki/Total_variation_denoising

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

References

*

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

Examples

>>> import skimage
>>> camera = skimage.data.camera().astype(float)
>>> camera += 0.5 * camera.std()*np.random.randn(*camera.shape)
>>> denoised_camera = tv_denoise(camera, weight=60.0)
hyperspy.misc.tv_denoise._tv_denoise_2d(im, weight=50, eps=0.0002, keep_type=False, n_iter_max=200)

Perform total-variation denoising

Parameters
  • im (ndarray) – input data to be denoised

  • 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 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 https://en.wikipedia.org/wiki/Total_variation_denoising

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

References

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

Examples

>>> import skimage
>>> camera = skimage.data.camera().astype(float)
>>> camera += 0.5 * camera.std()*np.random.randn(*ascent.shape)
>>> denoised_camera = tv_denoise(camera, weight=60.0)
hyperspy.misc.tv_denoise._tv_denoise_3d(im, weight=100, eps=0.0002, keep_type=False, n_iter_max=200)

Perform total-variation denoising on 3-D arrays

Parameters
  • im (ndarray) – 3-D input data to be denoised

  • 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 float

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

Returns

out – denoised array

Return type

ndarray

Notes

Rudin, Osher and Fatemi algorithm

Examples

First build synthetic noisy 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(float)
>>> mask += 0.2*np.random.randn(*mask.shape)
>>> res = tv_denoise_3d(mask, weight=100)
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 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 https://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 .

References

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 skimage
>>> camera = skimage.data.camera().astype(float)
>>> camera += 0.5 * camera.std()*np.random.randn(*camera.shape)
>>> denoised_camera = tv_denoise(camera, 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(float)
>>> mask += 0.2*np.random.randn(*mask.shape)
>>> res = tv_denoise_3d(mask, weight=100)