From 87936c0b096c57c70ed4b2e897465d218479827f Mon Sep 17 00:00:00 2001 From: "Gregory R. Lee" Date: Fri, 12 Aug 2016 08:22:18 -0400 Subject: [PATCH] TST: compare PSNR in the wavelet denoising tests --- skimage/restoration/tests/test_denoise.py | 29 ++++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/skimage/restoration/tests/test_denoise.py b/skimage/restoration/tests/test_denoise.py index 7ee1acd1..497a472d 100644 --- a/skimage/restoration/tests/test_denoise.py +++ b/skimage/restoration/tests/test_denoise.py @@ -3,7 +3,7 @@ from numpy.testing import run_module_suite, assert_raises, assert_equal from skimage import restoration, data, color, img_as_float, measure from skimage._shared._warnings import expected_warnings -from skimage.measure import compare_ssim +from skimage.measure import compare_psnr np.random.seed(1234) @@ -311,17 +311,28 @@ def test_no_denoising_for_small_h(): def test_wavelet_denoising(): for img, multichannel in [(astro_gray, False), (astro, True)]: - noisy = img.copy() + 0.1 * np.random.randn(*(img.shape)) + sigma = 0.1 + noisy = img.copy() + sigma * np.random.randn(*(img.shape)) noisy = np.clip(noisy, 0, 1) - # less energy in signal - denoised = restoration.denoise_wavelet(noisy, sigma=0.3, - multichannel=multichannel) - assert denoised.sum()**2 <= img.sum()**2 - # test changing noise_std (higher threshold, so less energy in signal) - res1 = restoration.denoise_wavelet(noisy, sigma=0.2, + # Verify that SNR is improved when true sigma is used + denoised = restoration.denoise_wavelet(noisy, sigma=sigma, + multichannel=multichannel) + psnr_noisy = compare_psnr(img, noisy) + psnr_denoised = compare_psnr(img, denoised) + assert psnr_denoised > psnr_noisy + + # Verify that SNR is improved with internally estimated sigma + denoised = restoration.denoise_wavelet(noisy, + multichannel=multichannel) + psnr_noisy = compare_psnr(img, noisy) + psnr_denoised = compare_psnr(img, denoised) + assert psnr_denoised > psnr_noisy + + # Test changing noise_std (higher threshold, so less energy in signal) + res1 = restoration.denoise_wavelet(noisy, sigma=2*sigma, multichannel=multichannel) - res2 = restoration.denoise_wavelet(noisy, sigma=0.1, + res2 = restoration.denoise_wavelet(noisy, sigma=sigma, multichannel=multichannel) assert (res1.sum()**2 <= res2.sum()**2)