Skip to content

Commit

Permalink
Starting to remove data.camera() from our tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdesiqueira committed Aug 13, 2020
1 parent 2e5e601 commit c7cab1e
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 122 deletions.
2 changes: 1 addition & 1 deletion skimage/color/tests/test_adapt_rgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion skimage/color/tests/test_colorconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion skimage/exposure/tests/test_exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions skimage/filters/tests/test_lpi_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions skimage/filters/tests/test_ridges.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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)

Expand Down
24 changes: 12 additions & 12 deletions skimage/measure/tests/test_structural_similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down
32 changes: 16 additions & 16 deletions skimage/metrics/tests/test_simple_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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():
Expand Down
24 changes: 12 additions & 12 deletions skimage/metrics/tests/test_structural_similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)))
Expand All @@ -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)))
Expand All @@ -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)))
Expand Down Expand Up @@ -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])
Expand Down
10 changes: 5 additions & 5 deletions skimage/registration/tests/test_phase_cross_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

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
from skimage._shared.fft import fftmodule as fft


def test_correlation():
reference_image = fft.fftn(camera())
reference_image = fft.fftn(grass())
shift = (-7, 12)
shifted_image = fourier_shift(reference_image, shift)

Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions skimage/restoration/tests/test_j_invariant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit c7cab1e

Please sign in to comment.