From 65021f481cfd4c1039a7cf9ffa08bbe010a9ddd9 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 31 May 2011 15:40:48 -0400 Subject: [PATCH 1/4] Remove print statements --- scikits/image/filter/tv_denoise.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scikits/image/filter/tv_denoise.py b/scikits/image/filter/tv_denoise.py index 0536d57d..da00586a 100644 --- a/scikits/image/filter/tv_denoise.py +++ b/scikits/image/filter/tv_denoise.py @@ -78,13 +78,11 @@ def _tv_denoise_3d(im, eps=2.e-4, weight=100, keep_type=False, n_iter_max=200): pz -= 1/6.*gz pz /= norm E /= float(im.size) - print E if i == 0: E_init = E E_previous = E else: if np.abs(E_previous - E) < eps * E_init: - print E_previous, E break else: E_previous = E @@ -176,7 +174,6 @@ def _tv_denoise_2d(im, weight=50, eps=2.e-4, keep_type=False, n_iter_max=200): py -= 0.25*gy py /= norm E /= float(im.size) - print E if i == 0: E_init = E E_previous = E @@ -186,7 +183,6 @@ def _tv_denoise_2d(im, weight=50, eps=2.e-4, keep_type=False, n_iter_max=200): else: E_previous = E i += 1 - print i if keep_type: return out.astype(im_type) else: From 637a568ae4725db2c4ac89e7b69bd1e63618ce14 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 31 May 2011 15:46:02 -0400 Subject: [PATCH 2/4] Fix order of keyword arguments to _tv_denoise_2d. tv_denoise passes keyword arguments `eps` and `weight` as positional arguments, but the order in _tv_denoise_2d was switched. --- scikits/image/filter/tv_denoise.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scikits/image/filter/tv_denoise.py b/scikits/image/filter/tv_denoise.py index da00586a..8114837c 100644 --- a/scikits/image/filter/tv_denoise.py +++ b/scikits/image/filter/tv_denoise.py @@ -92,7 +92,7 @@ def _tv_denoise_3d(im, eps=2.e-4, weight=100, keep_type=False, n_iter_max=200): else: return out -def _tv_denoise_2d(im, weight=50, eps=2.e-4, keep_type=False, n_iter_max=200): +def _tv_denoise_2d(im, eps=2.e-4, weight=50, keep_type=False, n_iter_max=200): """ Perform total-variation denoising From 680a89e5ceb2eb7843eca05549fbc90d92cedc4c Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 31 May 2011 15:50:09 -0400 Subject: [PATCH 3/4] Make test_tv_denoise_2d more strict. Original test only checked that tv_denoise reduced the total variation. This change makes sure that the reduction is significant. --- scikits/image/filter/tests/test_tv_denoise.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scikits/image/filter/tests/test_tv_denoise.py b/scikits/image/filter/tests/test_tv_denoise.py index 90325c80..d3a921a9 100644 --- a/scikits/image/filter/tests/test_tv_denoise.py +++ b/scikits/image/filter/tests/test_tv_denoise.py @@ -22,7 +22,7 @@ class TestTvDenoise(): grad = ndimage.morphological_gradient(lena, size=((3,3))) grad_denoised = ndimage.morphological_gradient(denoised_lena, size=((3,3))) # test if the total variation has decreased - assert np.sqrt((grad_denoised**2).sum()) < np.sqrt((grad**2).sum()) + assert np.sqrt((grad_denoised**2).sum()) < np.sqrt((grad**2).sum()) / 2 denoised_lena_int = F.tv_denoise(lena.astype(np.int32), \ weight=60.0, keep_type=True) assert denoised_lena_int.dtype is np.dtype('int32') From 8c0d79889694e6c26475fe1c83745b276e018166 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Thu, 23 Jun 2011 11:15:31 -0400 Subject: [PATCH 4/4] Reorder eps and weight keyword args to tv_denoise --- scikits/image/filter/tv_denoise.py | 34 +++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/scikits/image/filter/tv_denoise.py b/scikits/image/filter/tv_denoise.py index 8114837c..f2987b55 100644 --- a/scikits/image/filter/tv_denoise.py +++ b/scikits/image/filter/tv_denoise.py @@ -1,6 +1,6 @@ import numpy as np -def _tv_denoise_3d(im, eps=2.e-4, weight=100, keep_type=False, n_iter_max=200): +def _tv_denoise_3d(im, weight=100, eps=2.e-4, keep_type=False, n_iter_max=200): """ Perform total-variation denoising on 3-D arrays @@ -9,15 +9,15 @@ def _tv_denoise_3d(im, eps=2.e-4, weight=100, keep_type=False, n_iter_max=200): 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 - weight: float, optional - denoising weight. The greater ``weight``, the more denoising (at - the expense of fidelity to ``input``) - 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 @@ -92,7 +92,7 @@ def _tv_denoise_3d(im, eps=2.e-4, weight=100, keep_type=False, n_iter_max=200): else: return out -def _tv_denoise_2d(im, eps=2.e-4, weight=50, keep_type=False, n_iter_max=200): +def _tv_denoise_2d(im, weight=50, eps=2.e-4, keep_type=False, n_iter_max=200): """ Perform total-variation denoising @@ -101,15 +101,15 @@ def _tv_denoise_2d(im, eps=2.e-4, weight=50, keep_type=False, n_iter_max=200): 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 - weight: float, optional - denoising weight. The greater ``weight``, the more denoising (at - the expense of fidelity to ``input``) - 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 @@ -188,7 +188,7 @@ def _tv_denoise_2d(im, eps=2.e-4, weight=50, keep_type=False, n_iter_max=200): else: return out -def tv_denoise(im, eps=2.e-4, weight=50, keep_type=False, n_iter_max=200): +def tv_denoise(im, weight=50, eps=2.e-4, keep_type=False, n_iter_max=200): """ Perform total-variation denoising on 2-d and 3-d images @@ -199,15 +199,15 @@ def tv_denoise(im, eps=2.e-4, weight=50, keep_type=False, n_iter_max=200): 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 - weight: float, optional - denoising weight. The greater ``weight``, the more denoising (at - the expense of fidelity to ``input``) - 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 @@ -261,9 +261,9 @@ def tv_denoise(im, eps=2.e-4, weight=50, keep_type=False, n_iter_max=200): """ if im.ndim == 2: - return _tv_denoise_2d(im, eps, weight, keep_type, n_iter_max) + return _tv_denoise_2d(im, weight, eps, keep_type, n_iter_max) elif im.ndim == 3: - return _tv_denoise_3d(im, eps, weight, keep_type, n_iter_max) + return _tv_denoise_3d(im, weight, eps, keep_type, n_iter_max) else: raise ValueError('only 2-d and 3-d images may be denoised with this function')