"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "skimage/restoration/_denoise.py" between
scikit-image-0.19.1.tar.gz and scikit-image-0.19.2.tar.gz

About: scikit-image is a collection of algorithms for image processing in Python.

_denoise.py  (scikit-image-0.19.1):_denoise.py  (scikit-image-0.19.2)
skipping to change at line 347 skipping to change at line 347
out[..., c] = channel_out[..., 0] out[..., c] = channel_out[..., 0]
else: else:
image = np.ascontiguousarray(image) image = np.ascontiguousarray(image)
_denoise_tv_bregman(image, image.dtype.type(weight), max_num_iter, eps, _denoise_tv_bregman(image, image.dtype.type(weight), max_num_iter, eps,
isotropic, out) isotropic, out)
return np.squeeze(out[1:-1, 1:-1]) return np.squeeze(out[1:-1, 1:-1])
def _denoise_tv_chambolle_nd(image, weight=0.1, eps=2.e-4, n_iter_max=200): def _denoise_tv_chambolle_nd(image, weight=0.1, eps=2.e-4, max_num_iter=200):
"""Perform total-variation denoising on n-dimensional images. """Perform total-variation denoising on n-dimensional images.
Parameters Parameters
---------- ----------
image : ndarray image : ndarray
n-D input data to be denoised. n-D input data to be denoised.
weight : float, optional weight : float, optional
Denoising weight. The greater `weight`, the more denoising (at Denoising weight. The greater `weight`, the more denoising (at
the expense of fidelity to `input`). the expense of fidelity to `input`).
eps : float, optional eps : float, optional
Relative difference of the value of the cost function that determines Relative difference of the value of the cost function that determines
the stop criterion. The algorithm stops when: the stop criterion. The algorithm stops when:
(E_(n-1) - E_n) < eps * E_0 (E_(n-1) - E_n) < eps * E_0
n_iter_max : int, optional max_num_iter : int, optional
Maximal number of iterations used for the optimization. Maximal number of iterations used for the optimization.
Returns Returns
------- -------
out : ndarray out : ndarray
Denoised array of floats. Denoised array of floats.
Notes Notes
----- -----
Rudin, Osher and Fatemi algorithm. Rudin, Osher and Fatemi algorithm.
""" """
ndim = image.ndim ndim = image.ndim
p = np.zeros((image.ndim, ) + image.shape, dtype=image.dtype) p = np.zeros((image.ndim, ) + image.shape, dtype=image.dtype)
g = np.zeros_like(p) g = np.zeros_like(p)
d = np.zeros_like(image) d = np.zeros_like(image)
i = 0 i = 0
while i < n_iter_max: while i < max_num_iter:
if i > 0: if i > 0:
# d will be the (negative) divergence of p # d will be the (negative) divergence of p
d = -p.sum(0) d = -p.sum(0)
slices_d = [slice(None), ] * ndim slices_d = [slice(None), ] * ndim
slices_p = [slice(None), ] * (ndim + 1) slices_p = [slice(None), ] * (ndim + 1)
for ax in range(ndim): for ax in range(ndim):
slices_d[ax] = slice(1, None) slices_d[ax] = slice(1, None)
slices_p[ax+1] = slice(0, -1) slices_p[ax+1] = slice(0, -1)
slices_p[0] = ax slices_p[0] = ax
d[tuple(slices_d)] += p[tuple(slices_p)] d[tuple(slices_d)] += p[tuple(slices_p)]
skipping to change at line 427 skipping to change at line 427
E_init = E E_init = E
E_previous = E E_previous = E
else: else:
if np.abs(E_previous - E) < eps * E_init: if np.abs(E_previous - E) < eps * E_init:
break break
else: else:
E_previous = E E_previous = E
i += 1 i += 1
return out return out
@utils.deprecate_kwarg({'n_iter_max': 'max_num_iter'}, removed_version="1.0",
deprecated_version="0.19.2")
@utils.deprecate_multichannel_kwarg(multichannel_position=4) @utils.deprecate_multichannel_kwarg(multichannel_position=4)
def denoise_tv_chambolle(image, weight=0.1, eps=2.e-4, n_iter_max=200, def denoise_tv_chambolle(image, weight=0.1, eps=2.e-4, max_num_iter=200,
multichannel=False, *, channel_axis=None): multichannel=False, *, channel_axis=None):
"""Perform total-variation denoising on n-dimensional images. """Perform total-variation denoising on n-dimensional images.
Parameters Parameters
---------- ----------
image : ndarray of ints, uints or floats image : ndarray of ints, uints or floats
Input data to be denoised. `image` can be of any numeric type, Input data to be denoised. `image` can be of any numeric type,
but it is cast into an ndarray of floats for the computation but it is cast into an ndarray of floats for the computation
of the denoised image. of the denoised image.
weight : float, optional weight : float, optional
Denoising weight. The greater `weight`, the more denoising (at Denoising weight. The greater `weight`, the more denoising (at
the expense of fidelity to `input`). the expense of fidelity to `input`).
eps : float, optional eps : float, optional
Relative difference of the value of the cost function that Relative difference of the value of the cost function that
determines the stop criterion. The algorithm stops when: determines the stop criterion. The algorithm stops when:
(E_(n-1) - E_n) < eps * E_0 (E_(n-1) - E_n) < eps * E_0
n_iter_max : int, optional max_num_iter : int, optional
Maximal number of iterations used for the optimization. Maximal number of iterations used for the optimization.
multichannel : bool, optional multichannel : bool, optional
Apply total-variation denoising separately for each channel. This Apply total-variation denoising separately for each channel. This
option should be true for color images, otherwise the denoising is option should be true for color images, otherwise the denoising is
also applied in the channels dimension. This argument is deprecated: also applied in the channels dimension. This argument is deprecated:
specify `channel_axis` instead. specify `channel_axis` instead.
channel_axis : int or None, optional channel_axis : int or None, optional
If None, the image is assumed to be a grayscale (single channel) image. If None, the image is assumed to be a grayscale (single channel) image.
Otherwise, this parameter indicates which axis of the array corresponds Otherwise, this parameter indicates which axis of the array corresponds
to channels. to channels.
skipping to change at line 524 skipping to change at line 526
# enforce float16->float32 and float128->float64 # enforce float16->float32 and float128->float64
float_dtype = _supported_float_type(image.dtype) float_dtype = _supported_float_type(image.dtype)
image = image.astype(float_dtype, copy=False) image = image.astype(float_dtype, copy=False)
if channel_axis is not None: if channel_axis is not None:
channel_axis = channel_axis % image.ndim channel_axis = channel_axis % image.ndim
_at = functools.partial(utils.slice_at_axis, axis=channel_axis) _at = functools.partial(utils.slice_at_axis, axis=channel_axis)
out = np.zeros_like(image) out = np.zeros_like(image)
for c in range(image.shape[channel_axis]): for c in range(image.shape[channel_axis]):
out[_at(c)] = _denoise_tv_chambolle_nd(image[_at(c)], weight, eps, out[_at(c)] = _denoise_tv_chambolle_nd(image[_at(c)], weight, eps,
n_iter_max) max_num_iter)
else: else:
out = _denoise_tv_chambolle_nd(image, weight, eps, n_iter_max) out = _denoise_tv_chambolle_nd(image, weight, eps, max_num_iter)
return out return out
def _bayes_thresh(details, var): def _bayes_thresh(details, var):
"""BayesShrink threshold for a zero-mean details coeff array.""" """BayesShrink threshold for a zero-mean details coeff array."""
# Equivalent to: dvar = np.var(details) for 0-mean details array # Equivalent to: dvar = np.var(details) for 0-mean details array
dvar = np.mean(details*details) dvar = np.mean(details*details)
eps = np.finfo(details.dtype).eps eps = np.finfo(details.dtype).eps
thresh = var / np.sqrt(max(dvar - var, eps)) thresh = var / np.sqrt(max(dvar - var, eps))
return thresh return thresh
 End of changes. 8 change blocks. 
7 lines changed or deleted 9 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)