skimage2.restoration.denoise_tv_chambolle#
- skimage2.restoration.denoise_tv_chambolle(image, weight=0.1, eps=0.0002, max_num_iter=200, *, channel_axis=None)[source]#
Perform total variation denoising in nD.
Given \(f\), a noisy image (input data), total variation denoising (also known as total variation regularization) aims to find an image \(u\) with less total variation than \(f\), under the constraint that \(u\) remain similar to \(f\). This can be expressed by the RudinâOsherâFatemi (ROF) minimization problem:
\[\min_{u} \sum_{i=0}^{N-1} \left( \left| \nabla{u_i} \right| + \frac{\lambda}{2}(f_i - u_i)^2 \right)\]where \(\lambda\) is a positive parameter. The first term of this cost function is the total variation; the second term represents data fidelity. As \(\lambda \to 0\), the total variation term dominates, forcing the solution to have smaller total variation, at the expense of looking less like the input data.
This code is an implementation of the algorithm proposed by Chambolle in [1] to solve the ROF problem.
- Parameters:
- imagendarray
Input image to be denoised. If its dtype is not float, it gets converted with
skimage2.util.img_as_float().- weightfloat, optional
Denoising weight. It is equal to \(\frac{1}{\lambda}\). Therefore, the greater the
weight, the more denoising (at the expense of fidelity toimage).- epsfloat, optional
Tolerance \(\varepsilon > 0\) for the stop criterion (compares to absolute value of relative difference of the cost function \(E\)): The algorithm stops when \(|E_{n-1} - E_n| < \varepsilon * E_0\).
- max_num_iterint, optional
Maximal number of iterations used for the optimization.
- channel_axisint or None, optional
If
None, the image is assumed to be grayscale (single-channel). Otherwise, this parameter indicates which axis of the array corresponds to channels.Added in version 0.19:
channel_axiswas added in 0.19.
- Returns:
- undarray
Denoised image.
See also
denoise_tv_bregmanPerform total variation denoising using split-Bregman optimization.
Notes
Make sure to set the
channel_axisparameter appropriately for color images.The principle of total variation denoising is explained in [2]. It is about minimizing the total variation of an 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.
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 on astronaut image:
>>> from _skimage2 import color, data >>> img = color.rgb2gray(data.astronaut())[:50, :50] >>> rng = np.random.default_rng() >>> img += 0.5 * img.std() * rng.standard_normal(img.shape) >>> denoised_img = denoise_tv_chambolle(img, weight=60)
3D example on synthetic data:
>>> x, y, z = np.ogrid[0:20, 0:20, 0:20] >>> mask = (x - 22)**2 + (y - 20)**2 + (z - 17)**2 < 8**2 >>> mask = mask.astype(float) >>> rng = np.random.default_rng() >>> mask += 0.2 * rng.standard_normal(mask.shape) >>> res = denoise_tv_chambolle(mask, weight=100)