From 48bfe20ed741a50f4ee32d21ab41c99c8787edc8 Mon Sep 17 00:00:00 2001 From: "Gregory R. Lee" Date: Fri, 12 Aug 2016 08:34:43 -0400 Subject: [PATCH] TST: add basic wavelet denoising tests for 1D through 4D inputs --- skimage/restoration/tests/test_denoise.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/skimage/restoration/tests/test_denoise.py b/skimage/restoration/tests/test_denoise.py index 497a472d..acbd44b3 100644 --- a/skimage/restoration/tests/test_denoise.py +++ b/skimage/restoration/tests/test_denoise.py @@ -312,7 +312,7 @@ def test_no_denoising_for_small_h(): def test_wavelet_denoising(): for img, multichannel in [(astro_gray, False), (astro, True)]: sigma = 0.1 - noisy = img.copy() + sigma * np.random.randn(*(img.shape)) + noisy = img + sigma * np.random.randn(*(img.shape)) noisy = np.clip(noisy, 0, 1) # Verify that SNR is improved when true sigma is used @@ -337,5 +337,22 @@ def test_wavelet_denoising(): assert (res1.sum()**2 <= res2.sum()**2) +def test_wavelet_denoising_nd(): + for ndim in range(1, 5): + # Generate a very simple test image + img = 0.2*np.ones((16, )*ndim) + img[[slice(5, 13), ] * ndim] = 0.8 + + sigma = 0.1 + noisy = img + sigma * np.random.randn(*(img.shape)) + noisy = np.clip(noisy, 0, 1) + + # Verify that SNR is improved with internally estimated sigma + denoised = restoration.denoise_wavelet(noisy) + psnr_noisy = compare_psnr(img, noisy) + psnr_denoised = compare_psnr(img, denoised) + assert psnr_denoised > psnr_noisy + + if __name__ == "__main__": run_module_suite()