diff --git a/skimage/color/tests/test_adapt_rgb.py b/skimage/color/tests/test_adapt_rgb.py index f7102ed9e03..3b6a0c83f89 100644 --- a/skimage/color/tests/test_adapt_rgb.py +++ b/skimage/color/tests/test_adapt_rgb.py @@ -8,7 +8,7 @@ # Down-sample image for quicker testing. COLOR_IMAGE = data.astronaut()[::5, ::6] -GRAY_IMAGE = data.camera()[::5, ::5] +GRAY_IMAGE = data.grass()[::5, ::5] SIGMA = 3 smooth = partial(filters.gaussian, sigma=SIGMA) diff --git a/skimage/color/tests/test_colorconv.py b/skimage/color/tests/test_colorconv.py index 8b815e3f290..1a0aa1709ae 100644 --- a/skimage/color/tests/test_colorconv.py +++ b/skimage/color/tests/test_colorconv.py @@ -43,7 +43,7 @@ class TestColorconv(TestCase): img_rgb = data.colorwheel() - img_grayscale = data.camera() + img_grayscale = data.grass() img_rgba = np.array([[[0, 0.5, 1, 0], [0, 0.5, 1, 1], [0, 0.5, 1, 0.5]]]).astype(np.float) diff --git a/skimage/exposure/tests/test_exposure.py b/skimage/exposure/tests/test_exposure.py index 97c756a1ec9..3c8d2ca9623 100644 --- a/skimage/exposure/tests/test_exposure.py +++ b/skimage/exposure/tests/test_exposure.py @@ -121,7 +121,7 @@ def test_normalize(): np.random.seed(0) -test_img_int = data.camera() +test_img_int = data.grass() # squeeze image intensities to lower image contrast test_img = util.img_as_float(test_img_int) test_img = exposure.rescale_intensity(test_img / 5. + 100) diff --git a/skimage/filters/tests/test_lpi_filter.py b/skimage/filters/tests/test_lpi_filter.py index 92217a15b71..fcebabcaa92 100644 --- a/skimage/filters/tests/test_lpi_filter.py +++ b/skimage/filters/tests/test_lpi_filter.py @@ -3,12 +3,12 @@ import unittest from ..._shared import testing -from ...data import camera +from ...data import grass from ..lpi_filter import LPIFilter2D, inverse, wiener class TestLPIFilter2D(unittest.TestCase): - img = camera()[:50, :50] + img = grass()[:50, :50] def filt_func(self, r, c): return np.exp(-np.hypot(r, c) / 1) diff --git a/skimage/filters/tests/test_ridges.py b/skimage/filters/tests/test_ridges.py index 677bc72a671..b6c280ab1de 100644 --- a/skimage/filters/tests/test_ridges.py +++ b/skimage/filters/tests/test_ridges.py @@ -2,7 +2,7 @@ import numpy as np from numpy.testing import assert_allclose, assert_array_less, assert_equal from skimage.filters import meijering, sato, frangi, hessian -from skimage.data import camera, retina +from skimage.data import grass, retina from skimage.util import crop, invert from skimage.color import rgb2gray from skimage._shared._warnings import expected_warnings @@ -164,9 +164,9 @@ def test_3d_linearity(): atol=1e-3) -def test_2d_cropped_camera_image(): +def test_2d_cropped_grass_image(): - a_black = crop(camera(), ((206, 206), (206, 206))) + a_black = crop(grass(), ((206, 206), (206, 206))) a_white = invert(a_black) zeros = np.zeros((100, 100)) @@ -187,9 +187,9 @@ def test_2d_cropped_camera_image(): ones, atol=1 - 1e-7) -def test_3d_cropped_camera_image(): +def test_3d_cropped_grass_image(): - a_black = crop(camera(), ((206, 206), (206, 206))) + a_black = crop(grass(), ((206, 206), (206, 206))) a_black = np.dstack([a_black, a_black, a_black]) a_white = invert(a_black) diff --git a/skimage/measure/tests/test_structural_similarity.py b/skimage/measure/tests/test_structural_similarity.py index 9d39ab561dc..fbb606c2a27 100644 --- a/skimage/measure/tests/test_structural_similarity.py +++ b/skimage/measure/tests/test_structural_similarity.py @@ -10,10 +10,10 @@ assert_array_almost_equal, fetch) np.random.seed(5) -cam = data.camera() +grass = data.grass() sigma = 20.0 -cam_noisy = np.clip(cam + sigma * np.random.randn(*cam.shape), 0, 255) -cam_noisy = cam_noisy.astype(cam.dtype) +grass_noisy = np.clip(grass + sigma * np.random.randn(*grass.shape), 0, 255) +grass_noisy = grass_noisy.astype(grass.dtype) np.random.seed(1234) @@ -163,7 +163,7 @@ def test_gaussian_mssim_vs_IPOL(): # Tests vs. imdiff result from the following IPOL article and code: # https://www.ipol.im/pub/art/2011/g_lmii/ mssim_IPOL = 0.327309966087341 - mssim = structural_similarity(cam, cam_noisy, gaussian_weights=True, + mssim = structural_similarity(grass, grass_noisy, gaussian_weights=True, use_sample_covariance=False) assert_almost_equal(mssim, mssim_IPOL, decimal=3) @@ -174,12 +174,12 @@ def test_gaussian_mssim_vs_author_ref(): https://ece.uwaterloo.ca/~z70wang/research/ssim/ Matlab test code: - img1 = imread('camera.png') - img2 = imread('camera_noisy.png') + img1 = imread('grass.png') + img2 = imread('grass_noisy.png') mssim = ssim_index(img1, img2) """ mssim_matlab = 0.327314295673357 - mssim = structural_similarity(cam, cam_noisy, gaussian_weights=True, + mssim = structural_similarity(grass, grass_noisy, gaussian_weights=True, use_sample_covariance=False) assert_almost_equal(mssim, mssim_matlab, decimal=10) @@ -193,7 +193,7 @@ def test_gaussian_mssim_and_gradient_vs_Matlab(): grad_matlab = ref['grad_matlab'] mssim_matlab = float(ref['mssim_matlab']) - mssim, grad = structural_similarity(cam, cam_noisy, gaussian_weights=True, + mssim, grad = structural_similarity(grass, grass_noisy, gaussian_weights=True, gradient=True, use_sample_covariance=False) @@ -206,18 +206,18 @@ def test_gaussian_mssim_and_gradient_vs_Matlab(): def test_mssim_vs_legacy(): # check that ssim with default options matches skimage 0.11 result mssim_skimage_0pt11 = 0.34192589699605191 - mssim = structural_similarity(cam, cam_noisy) + mssim = structural_similarity(grass, grass_noisy) assert_almost_equal(mssim, mssim_skimage_0pt11) def test_mssim_mixed_dtype(): - mssim = structural_similarity(cam, cam_noisy) + mssim = structural_similarity(grass, grass_noisy) with expected_warnings(['Inputs have mismatched dtype']): - mssim_mixed = structural_similarity(cam, cam_noisy.astype(np.float32)) + mssim_mixed = structural_similarity(grass, grass_noisy.astype(np.float32)) assert_almost_equal(mssim, mssim_mixed) # no warning when user supplies data_range - mssim_mixed = structural_similarity(cam, cam_noisy.astype(np.float32), + mssim_mixed = structural_similarity(grass, grass_noisy.astype(np.float32), data_range=255) assert_almost_equal(mssim, mssim_mixed) diff --git a/skimage/metrics/tests/test_simple_metrics.py b/skimage/metrics/tests/test_simple_metrics.py index 8f3a79a15b6..8fbeff53fff 100644 --- a/skimage/metrics/tests/test_simple_metrics.py +++ b/skimage/metrics/tests/test_simple_metrics.py @@ -9,42 +9,42 @@ np.random.seed(5) -cam = data.camera() +grass = data.grass() sigma = 20.0 -cam_noisy = np.clip(cam + sigma * np.random.randn(*cam.shape), 0, 255) -cam_noisy = cam_noisy.astype(cam.dtype) +grass_noisy = np.clip(grass + sigma * np.random.randn(*grass.shape), 0, 255) +grass_noisy = grass_noisy.astype(grass.dtype) def test_PSNR_vs_IPOL(): # Tests vs. imdiff result from the following IPOL article and code: # https://www.ipol.im/pub/art/2011/g_lmii/ p_IPOL = 22.4497 - p = peak_signal_noise_ratio(cam, cam_noisy) + p = peak_signal_noise_ratio(grass, grass_noisy) assert_almost_equal(p, p_IPOL, decimal=4) def test_PSNR_float(): - p_uint8 = peak_signal_noise_ratio(cam, cam_noisy) - p_float64 = peak_signal_noise_ratio(cam / 255., cam_noisy / 255., + p_uint8 = peak_signal_noise_ratio(grass, grass_noisy) + p_float64 = peak_signal_noise_ratio(grass / 255., grass_noisy / 255., data_range=1) assert_almost_equal(p_uint8, p_float64, decimal=5) # mixed precision inputs - p_mixed = peak_signal_noise_ratio(cam / 255., np.float32(cam_noisy / 255.), + p_mixed = peak_signal_noise_ratio(grass / 255., np.float32(grass_noisy / 255.), data_range=1) assert_almost_equal(p_mixed, p_float64, decimal=5) # mismatched dtype results in a warning if data_range is unspecified with expected_warnings(['Inputs have mismatched dtype']): - p_mixed = peak_signal_noise_ratio(cam / 255., - np.float32(cam_noisy / 255.)) + p_mixed = peak_signal_noise_ratio(grass / 255., + np.float32(grass_noisy / 255.)) assert_almost_equal(p_mixed, p_float64, decimal=5) def test_PSNR_errors(): # shape mismatch with testing.raises(ValueError): - peak_signal_noise_ratio(cam, cam[:-1, :]) + peak_signal_noise_ratio(grass, grass[:-1, :]) def test_NRMSE(): @@ -64,12 +64,12 @@ def test_NRMSE(): def test_NRMSE_no_int_overflow(): - camf = cam.astype(np.float32) - cam_noisyf = cam_noisy.astype(np.float32) - assert_almost_equal(mean_squared_error(cam, cam_noisy), - mean_squared_error(camf, cam_noisyf)) - assert_almost_equal(normalized_root_mse(cam, cam_noisy), - normalized_root_mse(camf, cam_noisyf)) + grassf = grass.astype(np.float32) + grass_noisyf = grass_noisy.astype(np.float32) + assert_almost_equal(mean_squared_error(grass, grass_noisy), + mean_squared_error(grassf, grass_noisyf)) + assert_almost_equal(normalized_root_mse(grass, grass_noisy), + normalized_root_mse(grassf, grass_noisyf)) def test_NRMSE_errors(): diff --git a/skimage/metrics/tests/test_structural_similarity.py b/skimage/metrics/tests/test_structural_similarity.py index be1352e711e..389cb48cd9b 100644 --- a/skimage/metrics/tests/test_structural_similarity.py +++ b/skimage/metrics/tests/test_structural_similarity.py @@ -10,10 +10,10 @@ assert_array_almost_equal, fetch) np.random.seed(5) -cam = data.camera() +grass = data.grass() sigma = 20.0 -cam_noisy = np.clip(cam + sigma * np.random.randn(*cam.shape), 0, 255) -cam_noisy = cam_noisy.astype(cam.dtype) +grass_noisy = np.clip(grass + sigma * np.random.randn(*grass.shape), 0, 255) +grass_noisy = grass_noisy.astype(grass.dtype) np.random.seed(1234) @@ -161,7 +161,7 @@ def test_gaussian_structural_similarity_vs_IPOL(): # Tests vs. imdiff result from the following IPOL article and code: # https://www.ipol.im/pub/art/2011/g_lmii/ mssim_IPOL = 0.327309966087341 - mssim = structural_similarity(cam, cam_noisy, gaussian_weights=True, + mssim = structural_similarity(grass, grass_noisy, gaussian_weights=True, use_sample_covariance=False) assert_almost_equal(mssim, mssim_IPOL, decimal=3) @@ -172,12 +172,12 @@ def test_gaussian_mssim_vs_author_ref(): https://ece.uwaterloo.ca/~z70wang/research/ssim/ Matlab test code: - img1 = imread('camera.png') - img2 = imread('camera_noisy.png') + img1 = imread('grassera.png') + img2 = imread('grassera_noisy.png') mssim = structural_similarity_index(img1, img2) """ mssim_matlab = 0.327314295673357 - mssim = structural_similarity(cam, cam_noisy, gaussian_weights=True, + mssim = structural_similarity(grass, grass_noisy, gaussian_weights=True, use_sample_covariance=False) assert_almost_equal(mssim, mssim_matlab, decimal=10) @@ -191,7 +191,7 @@ def test_gaussian_mssim_and_gradient_vs_Matlab(): grad_matlab = ref['grad_matlab'] mssim_matlab = float(ref['mssim_matlab']) - mssim, grad = structural_similarity(cam, cam_noisy, gaussian_weights=True, + mssim, grad = structural_similarity(grass, grass_noisy, gaussian_weights=True, gradient=True, use_sample_covariance=False) @@ -204,19 +204,19 @@ def test_gaussian_mssim_and_gradient_vs_Matlab(): def test_mssim_vs_legacy(): # check that ssim with default options matches skimage 0.11 result mssim_skimage_0pt11 = 0.34192589699605191 - mssim = structural_similarity(cam, cam_noisy) + mssim = structural_similarity(grass, grass_noisy) assert_almost_equal(mssim, mssim_skimage_0pt11) def test_mssim_mixed_dtype(): - mssim = structural_similarity(cam, cam_noisy) + mssim = structural_similarity(grass, grass_noisy) with expected_warnings(['Inputs have mismatched dtype']): - mssim_mixed = structural_similarity(cam, cam_noisy.astype(np.float32)) + mssim_mixed = structural_similarity(grass, grass_noisy.astype(np.float32)) assert_almost_equal(mssim, mssim_mixed) # no warning when user supplies data_range mssim_mixed = structural_similarity( - cam, cam_noisy.astype(np.float32), data_range=255) + grass, grass_noisy.astype(np.float32), data_range=255) assert_almost_equal(mssim, mssim_mixed) diff --git a/skimage/registration/tests/test_masked_phase_cross_correlation.py b/skimage/registration/tests/test_masked_phase_cross_correlation.py index 4923ed7b20a..71d6a5e9adc 100644 --- a/skimage/registration/tests/test_masked_phase_cross_correlation.py +++ b/skimage/registration/tests/test_masked_phase_cross_correlation.py @@ -2,7 +2,7 @@ from scipy.ndimage import fourier_shift from skimage._shared import testing from skimage._shared.testing import assert_equal, fetch, expected_warnings -from skimage.data import camera, stereo_motorcycle +from skimage.data import grass, stereo_motorcycle from skimage.registration import phase_cross_correlation from skimage.registration._masked_phase_cross_correlation import ( _masked_phase_cross_correlation as masked_register_translation, @@ -24,7 +24,7 @@ def test_detrecated_masked_register_translation(): def test_masked_registration_vs_phase_cross_correlation(): """masked_register_translation should give the same results as phase_cross_correlation in the case of trivial masks.""" - reference_image = camera() + reference_image = grass() shift = (-7, 12) shifted = np.real(fft.ifft2(fourier_shift( fft.fft2(reference_image), shift))) @@ -45,7 +45,7 @@ def test_masked_registration_random_masks(): # See random number generator for reproducible results np.random.seed(23) - reference_image = camera() + reference_image = grass() shift = (-7, 12) shifted = np.real(fft.ifft2(fourier_shift( fft.fft2(reference_image), shift))) @@ -70,7 +70,7 @@ def test_masked_registration_random_masks_non_equal_sizes(): # See random number generator for reproducible results np.random.seed(23) - reference_image = camera() + reference_image = grass() shift = (-7, 12) shifted = np.real(fft.ifft2(fourier_shift( fft.fft2(reference_image), shift))) @@ -243,7 +243,7 @@ def test_cross_correlate_masked_autocorrelation_trivial_masks(): # See random number generator for reproducible results np.random.seed(23) - arr1 = camera() + arr1 = grass() # Random masks with 75% of pixels being valid m1 = np.random.choice([True, False], arr1.shape, p=[3 / 4, 1 / 4]) diff --git a/skimage/registration/tests/test_phase_cross_correlation.py b/skimage/registration/tests/test_phase_cross_correlation.py index 56dbed9d0bd..2dbe8824c83 100644 --- a/skimage/registration/tests/test_phase_cross_correlation.py +++ b/skimage/registration/tests/test_phase_cross_correlation.py @@ -3,7 +3,7 @@ from skimage.registration._phase_cross_correlation import ( phase_cross_correlation, _upsampled_dft) -from skimage.data import camera, binary_blobs +from skimage.data import grass, binary_blobs from scipy.ndimage import fourier_shift from skimage.util.dtype import img_as_float from skimage._shared import testing @@ -11,7 +11,7 @@ def test_correlation(): - reference_image = fft.fftn(camera()) + reference_image = fft.fftn(grass()) shift = (-7, 12) shifted_image = fourier_shift(reference_image, shift) @@ -23,7 +23,7 @@ def test_correlation(): def test_subpixel_precision(): - reference_image = fft.fftn(camera()) + reference_image = fft.fftn(grass()) subpixel_shift = (-2.4, 1.32) shifted_image = fourier_shift(reference_image, subpixel_shift) @@ -36,7 +36,7 @@ def test_subpixel_precision(): def test_real_input(): - reference_image = camera() + reference_image = grass() subpixel_shift = (-2.4, 1.32) shifted_image = fourier_shift(fft.fftn(reference_image), subpixel_shift) shifted_image = fft.ifftn(shifted_image) @@ -50,7 +50,7 @@ def test_real_input(): def test_size_one_dimension_input(): # take a strip of the input image - reference_image = fft.fftn(camera()[:, 15]).reshape((-1, 1)) + reference_image = fft.fftn(grass()[:, 15]).reshape((-1, 1)) subpixel_shift = (-2.4, 4) shifted_image = fourier_shift(reference_image, subpixel_shift) diff --git a/skimage/restoration/tests/test_j_invariant.py b/skimage/restoration/tests/test_j_invariant.py index 5630eb82c94..9bc92f72109 100644 --- a/skimage/restoration/tests/test_j_invariant.py +++ b/skimage/restoration/tests/test_j_invariant.py @@ -3,14 +3,14 @@ from skimage._shared.testing import assert_ from skimage.data import binary_blobs -from skimage.data import camera, chelsea +from skimage.data import grass, chelsea from skimage.metrics import mean_squared_error as mse from skimage.restoration import (calibrate_denoiser, denoise_wavelet) from skimage.restoration.j_invariant import _invariant_denoise from skimage.util import img_as_float, random_noise -test_img = img_as_float(camera()) +test_img = img_as_float(grass()) test_img_color = img_as_float(chelsea()) test_img_3d = img_as_float(binary_blobs(64, n_dim=3)) / 2 noisy_img = random_noise(test_img, mode='gaussian', var=0.01) diff --git a/skimage/restoration/tests/test_restoration.py b/skimage/restoration/tests/test_restoration.py index 44242494460..711113140f5 100644 --- a/skimage/restoration/tests/test_restoration.py +++ b/skimage/restoration/tests/test_restoration.py @@ -5,11 +5,11 @@ import skimage from skimage.color import rgb2gray -from skimage.data import astronaut, camera, image_fetcher +from skimage.data import astronaut, grass, image_fetcher from skimage import restoration from skimage.restoration import uft -test_img = skimage.img_as_float(camera()) +test_img = skimage.img_as_float(grass()) def test_wiener(): @@ -63,7 +63,7 @@ def test_image_shape(): point[2, 2] = 1. psf = ndi.gaussian_filter(point, sigma=1.) # image shape: (45, 45), as reported in #1172 - image = skimage.img_as_float(camera()[110:155, 225:270]) # just the face + image = skimage.img_as_float(grass()[110:155, 225:270]) image_conv = ndi.convolve(image, psf) deconv_sup = restoration.wiener(image_conv, psf, 1) deconv_un = restoration.unsupervised_wiener(image_conv, psf)[0] diff --git a/skimage/util/tests/test_random_noise.py b/skimage/util/tests/test_random_noise.py index 495bf359d34..90b865c17ee 100644 --- a/skimage/util/tests/test_random_noise.py +++ b/skimage/util/tests/test_random_noise.py @@ -2,28 +2,28 @@ from skimage._shared.testing import assert_array_equal, assert_allclose import numpy as np -from skimage.data import camera +from skimage.data import grass from skimage.util import random_noise, img_as_float def test_set_seed(): seed = 42 - cam = camera() - test = random_noise(cam, seed=seed) - assert_array_equal(test, random_noise(cam, seed=seed)) + data = grass() + test = random_noise(data, seed=seed) + assert_array_equal(test, random_noise(data, seed=seed)) def test_salt(): seed = 42 - cam = img_as_float(camera()) - cam_noisy = random_noise(cam, seed=seed, mode='salt', amount=0.15) - saltmask = cam != cam_noisy + data = img_as_float(grass()) + data_noisy = random_noise(data, seed=seed, mode='salt', amount=0.15) + saltmask = data != data_noisy # Ensure all changes are to 1.0 - assert_allclose(cam_noisy[saltmask], np.ones(saltmask.sum())) + assert_allclose(data_noisy[saltmask], np.ones(saltmask.sum())) # Ensure approximately correct amount of noise was added - proportion = float(saltmask.sum()) / (cam.shape[0] * cam.shape[1]) + proportion = float(saltmask.sum()) / (data.shape[0] * data.shape[1]) assert 0.11 < proportion <= 0.15 @@ -42,44 +42,44 @@ def test_singleton_dim(): def test_pepper(): seed = 42 - cam = img_as_float(camera()) - data_signed = cam * 2. - 1. # Same image, on range [-1, 1] + data = img_as_float(grass()) + data_signed = data * 2. - 1. # Same image, on range [-1, 1] - cam_noisy = random_noise(cam, seed=seed, mode='pepper', amount=0.15) - peppermask = cam != cam_noisy + data_noisy = random_noise(data, seed=seed, mode='pepper', amount=0.15) + peppermask = data != data_noisy # Ensure all changes are to 1.0 - assert_allclose(cam_noisy[peppermask], np.zeros(peppermask.sum())) + assert_allclose(data_noisy[peppermask], np.zeros(peppermask.sum())) # Ensure approximately correct amount of noise was added - proportion = float(peppermask.sum()) / (cam.shape[0] * cam.shape[1]) + proportion = float(peppermask.sum()) / (data.shape[0] * data.shape[1]) assert 0.11 < proportion <= 0.15 # Check to make sure pepper gets added properly to signed images orig_zeros = (data_signed == -1).sum() - cam_noisy_signed = random_noise(data_signed, seed=seed, mode='pepper', + data_noisy_signed = random_noise(data_signed, seed=seed, mode='pepper', amount=.15) - proportion = (float((cam_noisy_signed == -1).sum() - orig_zeros) / - (cam.shape[0] * cam.shape[1])) + proportion = (float((data_noisy_signed == -1).sum() - orig_zeros) / + (data.shape[0] * data.shape[1])) assert 0.11 < proportion <= 0.15 def test_salt_and_pepper(): seed = 42 - cam = img_as_float(camera()) - cam_noisy = random_noise(cam, seed=seed, mode='s&p', amount=0.15, + data = img_as_float(grass()) + data_noisy = random_noise(data, seed=seed, mode='s&p', amount=0.15, salt_vs_pepper=0.25) - saltmask = np.logical_and(cam != cam_noisy, cam_noisy == 1.) - peppermask = np.logical_and(cam != cam_noisy, cam_noisy == 0.) + saltmask = np.logical_and(data != data_noisy, data_noisy == 1.) + peppermask = np.logical_and(data != data_noisy, data_noisy == 0.) # Ensure all changes are to 0. or 1. - assert_allclose(cam_noisy[saltmask], np.ones(saltmask.sum())) - assert_allclose(cam_noisy[peppermask], np.zeros(peppermask.sum())) + assert_allclose(data_noisy[saltmask], np.ones(saltmask.sum())) + assert_allclose(data_noisy[peppermask], np.zeros(peppermask.sum())) # Ensure approximately correct amount of noise was added proportion = float( - saltmask.sum() + peppermask.sum()) / (cam.shape[0] * cam.shape[1]) + saltmask.sum() + peppermask.sum()) / (data.shape[0] * data.shape[1]) assert 0.11 < proportion <= 0.18 # Verify the relative amount of salt vs. pepper is close to expected @@ -138,74 +138,74 @@ def test_speckle(): def test_poisson(): seed = 42 - data = camera() # 512x512 grayscale uint8 - cam_noisy = random_noise(data, mode='poisson', seed=seed) - cam_noisy2 = random_noise(data, mode='poisson', seed=seed, clip=False) + data = grass() # 512x512 grayscale uint8 + data_noisy = random_noise(data, mode='poisson', seed=seed) + data_noisy2 = random_noise(data, mode='poisson', seed=seed, clip=False) np.random.seed(seed=seed) expected = np.random.poisson(img_as_float(data) * 256) / 256. - assert_allclose(cam_noisy, np.clip(expected, 0., 1.)) - assert_allclose(cam_noisy2, expected) + assert_allclose(data_noisy, np.clip(expected, 0., 1.)) + assert_allclose(data_noisy2, expected) def test_clip_poisson(): seed = 42 - data = camera() # 512x512 grayscale uint8 + data = grass() # 512x512 grayscale uint8 data_signed = img_as_float(data) * 2. - 1. # Same image, on range [-1, 1] # Signed and unsigned, clipped - cam_poisson = random_noise(data, mode='poisson', seed=seed, clip=True) - cam_poisson2 = random_noise(data_signed, mode='poisson', seed=seed, + data_poisson = random_noise(data, mode='poisson', seed=seed, clip=True) + data_poisson2 = random_noise(data_signed, mode='poisson', seed=seed, clip=True) - assert (cam_poisson.max() == 1.) and (cam_poisson.min() == 0.) - assert (cam_poisson2.max() == 1.) and (cam_poisson2.min() == -1.) + assert (data_poisson.max() == 1.) and (data_poisson.min() == 0.) + assert (data_poisson2.max() == 1.) and (data_poisson2.min() == -1.) # Signed and unsigned, unclipped - cam_poisson = random_noise(data, mode='poisson', seed=seed, clip=False) - cam_poisson2 = random_noise(data_signed, mode='poisson', seed=seed, + data_poisson = random_noise(data, mode='poisson', seed=seed, clip=False) + data_poisson2 = random_noise(data_signed, mode='poisson', seed=seed, clip=False) - assert (cam_poisson.max() > 1.15) and (cam_poisson.min() == 0.) - assert (cam_poisson2.max() > 1.3) and (cam_poisson2.min() == -1.) + assert (data_poisson.max() > 1.15) and (data_poisson.min() == 0.) + assert (data_poisson2.max() > 1.3) and (data_poisson2.min() == -1.) def test_clip_gaussian(): seed = 42 - data = camera() # 512x512 grayscale uint8 + data = grass() data_signed = img_as_float(data) * 2. - 1. # Same image, on range [-1, 1] # Signed and unsigned, clipped - cam_gauss = random_noise(data, mode='gaussian', seed=seed, clip=True) - cam_gauss2 = random_noise(data_signed, mode='gaussian', seed=seed, + data_gauss = random_noise(data, mode='gaussian', seed=seed, clip=True) + data_gauss2 = random_noise(data_signed, mode='gaussian', seed=seed, clip=True) - assert (cam_gauss.max() == 1.) and (cam_gauss.min() == 0.) - assert (cam_gauss2.max() == 1.) and (cam_gauss2.min() == -1.) + assert (data_gauss.max() == 1.) and (data_gauss.min() == 0.) + assert (data_gauss2.max() == 1.) and (data_gauss2.min() == -1.) # Signed and unsigned, unclipped - cam_gauss = random_noise(data, mode='gaussian', seed=seed, clip=False) - cam_gauss2 = random_noise(data_signed, mode='gaussian', seed=seed, + data_gauss = random_noise(data, mode='gaussian', seed=seed, clip=False) + data_gauss2 = random_noise(data_signed, mode='gaussian', seed=seed, clip=False) - assert (cam_gauss.max() > 1.22) and (cam_gauss.min() < -0.36) - assert (cam_gauss2.max() > 1.219) and (cam_gauss2.min() < -1.337) + assert (data_gauss.max() > 1.22) and (data_gauss.min() < -0.36) + assert (data_gauss2.max() > 1.219) and (data_gauss2.min() < -1.337) def test_clip_speckle(): seed = 42 - data = camera() # 512x512 grayscale uint8 + data = grass() data_signed = img_as_float(data) * 2. - 1. # Same image, on range [-1, 1] # Signed and unsigned, clipped - cam_speckle = random_noise(data, mode='speckle', seed=seed, clip=True) - cam_speckle2 = random_noise(data_signed, mode='speckle', seed=seed, + data_speckle = random_noise(data, mode='speckle', seed=seed, clip=True) + data_speckle2 = random_noise(data_signed, mode='speckle', seed=seed, clip=True) - assert (cam_speckle.max() == 1.) and (cam_speckle.min() == 0.) - assert (cam_speckle2.max() == 1.) and (cam_speckle2.min() == -1.) + assert (data_speckle.max() == 1.) and (data_speckle.min() == 0.) + assert (data_speckle2.max() == 1.) and (data_speckle2.min() == -1.) # Signed and unsigned, unclipped - cam_speckle = random_noise(data, mode='speckle', seed=seed, clip=False) - cam_speckle2 = random_noise(data_signed, mode='speckle', seed=seed, + data_speckle = random_noise(data, mode='speckle', seed=seed, clip=False) + data_speckle2 = random_noise(data_signed, mode='speckle', seed=seed, clip=False) - assert (cam_speckle.max() > 1.219) and (cam_speckle.min() == 0.) - assert (cam_speckle2.max() > 1.219) and (cam_speckle2.min() < -1.306) + assert (data_speckle.max() > 1.219) and (data_speckle.min() == 0.) + assert (data_speckle2.max() > 1.219) and (data_speckle2.min() < -1.306) def test_bad_mode():