mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-04 13:14:23 +08:00
TST: compare PSNR in the wavelet denoising tests
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user