From 53742be9c632c668bae171d080bf4c75007aa0f9 Mon Sep 17 00:00:00 2001 From: "Gregory R. Lee" Date: Sun, 24 Jan 2016 02:24:37 -0500 Subject: [PATCH] fix axis bug in multichannel case and add a corresponding test --- skimage/restoration/_denoise.py | 2 +- skimage/restoration/tests/test_denoise.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/skimage/restoration/_denoise.py b/skimage/restoration/_denoise.py index acd25cb0..62985cc7 100644 --- a/skimage/restoration/_denoise.py +++ b/skimage/restoration/_denoise.py @@ -276,7 +276,7 @@ def denoise_tv_chambolle(im, weight=0.1, eps=2.e-4, n_iter_max=200, if multichannel: out = np.zeros_like(im) - for c in range(im.shape[2]): + for c in range(im.shape[-1]): out[..., c] = _denoise_tv_chambolle_nd(im[..., c], weight, eps, n_iter_max) else: diff --git a/skimage/restoration/tests/test_denoise.py b/skimage/restoration/tests/test_denoise.py index 9aa91526..5f4ce178 100644 --- a/skimage/restoration/tests/test_denoise.py +++ b/skimage/restoration/tests/test_denoise.py @@ -39,6 +39,15 @@ def test_denoise_tv_chambolle_multichannel(): multichannel=True) assert_equal(denoised[..., 0], denoised0) + # tile astronaut subset to generate 3D+channels data + astro3 = np.tile(astro[:64, :64, np.newaxis, :], [1, 1, 2, 1]) + # modify along tiled dimension to give non-zero gradient on 3rd axis + astro3[:, :, 0, :] = 2*astro3[:, :, 0, :] + denoised0 = restoration.denoise_tv_chambolle(astro3[..., 0], weight=0.1) + denoised = restoration.denoise_tv_chambolle(astro3, weight=0.1, + multichannel=True) + assert_equal(denoised[..., 0], denoised0) + def test_denoise_tv_chambolle_float_result_range(): # astronaut image