diff --git a/skimage/color/tests/test_colorconv.py b/skimage/color/tests/test_colorconv.py index 4bc01e78..63336a76 100644 --- a/skimage/color/tests/test_colorconv.py +++ b/skimage/color/tests/test_colorconv.py @@ -43,6 +43,8 @@ from skimage import data_dir, data import colorsys +np.random.seed(0) + def test_guess_spatial_dimensions(): im1 = np.zeros((5, 5)) @@ -223,7 +225,7 @@ class TestColorconv(TestCase): assert_equal(g.shape, (1, 1)) def test_rgb2grey_on_grey(self): - rgb2grey(np.random.random((5, 5))) + rgb2grey(np.random.rand(5, 5)) # test matrices for xyz2lab and lab2xyz generated using http://www.easyrgb.com/index.php?X=CALC # Note: easyrgb website displays xyz*100 @@ -349,7 +351,7 @@ def test_gray2rgb(): def test_gray2rgb_rgb(): - x = np.random.random((5, 5, 4)) + x = np.random.rand(5, 5, 4) y = gray2rgb(x) assert_equal(x, y) diff --git a/skimage/feature/tests/test_censure.py b/skimage/feature/tests/test_censure.py index 53c1c59b..95bfcda3 100644 --- a/skimage/feature/tests/test_censure.py +++ b/skimage/feature/tests/test_censure.py @@ -5,12 +5,13 @@ from skimage.feature import CENSURE img = moon() +np.random.seed(0) def test_censure_on_rectangular_images(): """Censure feature detector should work on 2D image of any shape.""" - rect_image = np.random.random((300, 200)) - square_image = np.random.random((200, 200)) + rect_image = np.random.rand(300, 200) + square_image = np.random.rand(200, 200) CENSURE().detect((square_image)) CENSURE().detect((rect_image)) diff --git a/skimage/feature/tests/test_peak.py b/skimage/feature/tests/test_peak.py index 98242a4d..ec130c66 100644 --- a/skimage/feature/tests/test_peak.py +++ b/skimage/feature/tests/test_peak.py @@ -5,6 +5,9 @@ import scipy.ndimage from skimage.feature import peak +np.random.seed(21) + + def test_trivial_case(): trivial = np.zeros((25, 25)) peak_indices = peak.peak_local_max(trivial, min_distance=1, indices=True) @@ -17,7 +20,7 @@ def test_noisy_peaks(): peak_locations = [(7, 7), (7, 13), (13, 7), (13, 13)] # image with noise of amplitude 0.8 and peaks of amplitude 1 - image = 0.8 * np.random.random((20, 20)) + image = 0.8 * np.random.rand(20, 20) for r, c in peak_locations: image[r, c] = 1 @@ -80,7 +83,6 @@ def test_num_peaks(): def test_reorder_labels(): - np.random.seed(21) image = np.random.uniform(size=(40, 60)) i, j = np.mgrid[0:40, 0:60] labels = 1 + (i >= 20) + (j >= 30) * 2 @@ -100,7 +102,6 @@ def test_reorder_labels(): def test_indices_with_labels(): - np.random.seed(21) image = np.random.uniform(size=(40, 60)) i, j = np.mgrid[0:40, 0:60] labels = 1 + (i >= 20) + (j >= 30) * 2 @@ -233,7 +234,6 @@ def test_adjacent_different_objects(): def test_four_quadrants(): - np.random.seed(21) image = np.random.uniform(size=(40, 60)) i, j = np.mgrid[0:40, 0:60] labels = 1 + (i >= 20) + (j >= 30) * 2 @@ -255,7 +255,6 @@ def test_disk(): '''regression test of img-1194, footprint = [1] Test peak.peak_local_max when every point is a local maximum ''' - np.random.seed(31) image = np.random.uniform(size=(10, 20)) footprint = np.array([[1]]) result = peak.peak_local_max(image, labels=np.ones((10, 20)), diff --git a/skimage/feature/tests/test_texture.py b/skimage/feature/tests/test_texture.py index dac511d4..788ccbc6 100644 --- a/skimage/feature/tests/test_texture.py +++ b/skimage/feature/tests/test_texture.py @@ -199,7 +199,7 @@ class TestLBP(): np.random.seed(13141516) # Create random image with known variance. - image = np.random.random((500, 500)) + image = np.random.rand(500, 500) target_std = 0.3 image = image / image.std() * target_std diff --git a/skimage/filter/_canny.py b/skimage/filter/_canny.py index 185bfd40..8dcd1570 100644 --- a/skimage/filter/_canny.py +++ b/skimage/filter/_canny.py @@ -112,7 +112,7 @@ def canny(image, sigma=1., low_threshold=None, high_threshold=None, mask=None): >>> # Generate noisy image of a square >>> im = np.zeros((256, 256)) >>> im[64:-64, 64:-64] = 1 - >>> im += 0.2 * np.random.random(im.shape) + >>> im += 0.2 * np.random.rand(*im.shape) >>> # First trial with the Canny filter, with the default smoothing >>> edges1 = filter.canny(im) >>> # Increase the smoothing for better results diff --git a/skimage/filter/rank/tests/test_rank.py b/skimage/filter/rank/tests/test_rank.py index 72f9afe6..5cbffd90 100644 --- a/skimage/filter/rank/tests/test_rank.py +++ b/skimage/filter/rank/tests/test_rank.py @@ -6,6 +6,8 @@ from skimage import data, util from skimage.morphology import cmorph, disk from skimage.filter import rank +np.random.seed(0) + def test_random_sizes(): # make sure the size is not a problem @@ -44,7 +46,7 @@ def test_random_sizes(): def test_compare_with_cmorph_dilate(): # compare the result of maximum filter with dilate - image = (np.random.random((100, 100)) * 256).astype(np.uint8) + image = (np.random.rand(100, 100) * 256).astype(np.uint8) out = np.empty_like(image) mask = np.ones(image.shape, dtype=np.uint8) @@ -58,7 +60,7 @@ def test_compare_with_cmorph_dilate(): def test_compare_with_cmorph_erode(): # compare the result of maximum filter with erode - image = (np.random.random((100, 100)) * 256).astype(np.uint8) + image = (np.random.rand(100, 100) * 256).astype(np.uint8) out = np.empty_like(image) mask = np.ones(image.shape, dtype=np.uint8) @@ -143,7 +145,7 @@ def test_inplace_output(): # rank filters are not supposed to filter inplace selem = disk(20) - image = (np.random.random((500, 500)) * 256).astype(np.uint8) + image = (np.random.rand(500, 500) * 256).astype(np.uint8) out = image assert_raises(NotImplementedError, rank.mean, image, selem, out=out) diff --git a/skimage/graph/tests/test_mcp.py b/skimage/graph/tests/test_mcp.py index 5c44abad..4dc69858 100644 --- a/skimage/graph/tests/test_mcp.py +++ b/skimage/graph/tests/test_mcp.py @@ -5,6 +5,7 @@ from numpy.testing import (assert_array_equal, import skimage.graph.mcp as mcp +np.random.seed(0) a = np.ones((8, 8), dtype=np.float32) a[1:-1, 1] = 0 a[1, 1:-1] = 0 @@ -133,15 +134,14 @@ def test_crashing(): def _test_random(shape): # Just tests for crashing -- not for correctness. - np.random.seed(0) - a = np.random.random(shape).astype(np.float32) + a = np.random.rand(*shape).astype(np.float32) starts = [[0] * len(shape), [-1] * len(shape), - (np.random.random(len(shape)) * shape).astype(int)] - ends = [(np.random.random(len(shape)) * shape).astype(int) + (np.random.rand(len(shape)) * shape).astype(int)] + ends = [(np.random.rand(len(shape)) * shape).astype(int) for i in range(4)] m = mcp.MCP(a, fully_connected=True) costs, offsets = m.find_costs(starts) - for point in [(np.random.random(len(shape)) * shape).astype(int) + for point in [(np.random.rand(len(shape)) * shape).astype(int) for i in range(4)]: m.traceback(point) m._reset() diff --git a/skimage/io/_io.py b/skimage/io/_io.py index 97f8718e..06da7adb 100644 --- a/skimage/io/_io.py +++ b/skimage/io/_io.py @@ -193,7 +193,7 @@ def show(): >>> import skimage.io as io >>> for i in range(4): - ... io.imshow(np.random.random((50, 50))) + ... io.imshow(np.random.rand(50, 50)) >>> io.show() # doctest: +SKIP ''' diff --git a/skimage/io/tests/test_freeimage.py b/skimage/io/tests/test_freeimage.py index 4e64bd16..a2d88db3 100644 --- a/skimage/io/tests/test_freeimage.py +++ b/skimage/io/tests/test_freeimage.py @@ -14,6 +14,8 @@ try: except RuntimeError: FI_available = False +np.random.seed(0) + def setup_module(self): """The effect of the `plugin.use` call may be overridden by later imports. @@ -62,7 +64,7 @@ def test_imread_uint16_big_endian(): @skipif(not FI_available) def test_write_multipage(): shape = (64, 64, 64) - x = np.ones(shape, dtype=np.uint8) * np.random.random(shape) * 255 + x = np.ones(shape, dtype=np.uint8) * np.random.rand(*shape) * 255 x = x.astype(np.uint8) f = NamedTemporaryFile(suffix='.tif') fname = f.name @@ -91,7 +93,7 @@ class TestSave: ]: tests = [(d, f) for d in dtype for f in format] for d, f in tests: - x = np.ones(shape, dtype=d) * np.random.random(shape) + x = np.ones(shape, dtype=d) * np.random.rand(*shape) if not np.issubdtype(d, float): x = (x * 255).astype(d) yield self.roundtrip, d, x, f diff --git a/skimage/io/tests/test_imread.py b/skimage/io/tests/test_imread.py index 206b800d..25ad870e 100644 --- a/skimage/io/tests/test_imread.py +++ b/skimage/io/tests/test_imread.py @@ -16,6 +16,8 @@ except ImportError: else: imread_available = True +np.random.seed(0) + def teardown(): reset_plugins() @@ -66,7 +68,7 @@ class TestSave: def test_imsave_roundtrip(self): dtype = np.uint8 for shape in [(10, 10), (10, 10, 3), (10, 10, 4)]: - x = np.ones(shape, dtype=dtype) * np.random.random(shape) + x = np.ones(shape, dtype=dtype) * np.random.rand(*shape) if np.issubdtype(dtype, float): yield self.roundtrip, x, 255 diff --git a/skimage/io/tests/test_pil.py b/skimage/io/tests/test_pil.py index 89147fd6..c5718388 100644 --- a/skimage/io/tests/test_pil.py +++ b/skimage/io/tests/test_pil.py @@ -21,6 +21,8 @@ except ImportError: else: PIL_available = True +np.random.seed(0) + def teardown(): reset_plugins() @@ -124,7 +126,7 @@ class TestSave: def test_imsave_roundtrip(self): for shape in [(10, 10), (10, 10, 3), (10, 10, 4)]: for dtype in (np.uint8, np.uint16, np.float32, np.float64): - x = np.ones(shape, dtype=dtype) * np.random.random(shape) + x = np.ones(shape, dtype=dtype) * np.random.rand(*shape) if np.issubdtype(dtype, float): yield self.roundtrip, dtype, x, 255 diff --git a/skimage/io/tests/test_plugin_util.py b/skimage/io/tests/test_plugin_util.py index 41f28339..30f67018 100644 --- a/skimage/io/tests/test_plugin_util.py +++ b/skimage/io/tests/test_plugin_util.py @@ -3,13 +3,15 @@ from skimage.io._plugins.util import prepare_for_display, WindowManager from numpy.testing import * import numpy as np +np.random.seed(0) + class TestPrepareForDisplay: def test_basic(self): - prepare_for_display(np.random.random((10, 10))) + prepare_for_display(np.random.rand(10, 10)) def test_dtype(self): - x = prepare_for_display(np.random.random((10, 15))) + x = prepare_for_display(np.random.rand(10, 15)) assert x.dtype == np.dtype(np.uint8) def test_grey(self): @@ -19,18 +21,18 @@ class TestPrepareForDisplay: assert x[3, 2, 0] == 255 def test_colour(self): - prepare_for_display(np.random.random((10, 10, 3))) + prepare_for_display(np.random.rand(10, 10, 3)) def test_alpha(self): - prepare_for_display(np.random.random((10, 10, 4))) + prepare_for_display(np.random.rand(10, 10, 4)) @raises(ValueError) def test_wrong_dimensionality(self): - prepare_for_display(np.random.random((10, 10, 1, 1))) + prepare_for_display(np.random.rand(10, 10, 1, 1)) @raises(ValueError) def test_wrong_depth(self): - prepare_for_display(np.random.random((10, 10, 5))) + prepare_for_display(np.random.rand(10, 10, 5)) class TestWindowManager: diff --git a/skimage/io/tests/test_simpleitk.py b/skimage/io/tests/test_simpleitk.py index 89f7416f..ab8cd592 100644 --- a/skimage/io/tests/test_simpleitk.py +++ b/skimage/io/tests/test_simpleitk.py @@ -15,6 +15,8 @@ except ImportError: else: sitk_available = True +np.random.seed(0) + def teardown(): reset_plugins() @@ -86,7 +88,7 @@ class TestSave: def test_imsave_roundtrip(self): for shape in [(10, 10), (10, 10, 3), (10, 10, 4)]: for dtype in (np.uint8, np.uint16, np.float32, np.float64): - x = np.ones(shape, dtype=dtype) * np.random.random(shape) + x = np.ones(shape, dtype=dtype) * np.random.rand(*shape) if np.issubdtype(dtype, float): yield self.roundtrip, dtype, x diff --git a/skimage/io/tests/test_tifffile.py b/skimage/io/tests/test_tifffile.py index 0f128bf1..7019f0c6 100644 --- a/skimage/io/tests/test_tifffile.py +++ b/skimage/io/tests/test_tifffile.py @@ -15,6 +15,8 @@ try: except ImportError: TF_available = False +np.random.seed(0) + def teardown(): sio.reset_plugins() @@ -49,7 +51,7 @@ class TestSave: def test_imsave_roundtrip(self): for shape in [(10, 10), (10, 10, 3), (10, 10, 4)]: for dtype in (np.uint8, np.uint16, np.float32, np.float64): - x = np.ones(shape, dtype=dtype) * np.random.random(shape) + x = np.ones(shape, dtype=dtype) * np.random.rand(*shape) if not np.issubdtype(dtype, float): x = (x * 255).astype(dtype) diff --git a/skimage/measure/fit.py b/skimage/measure/fit.py index 8f9ceb9c..e0118388 100644 --- a/skimage/measure/fit.py +++ b/skimage/measure/fit.py @@ -586,7 +586,8 @@ def ransac(data, model_class, min_samples, residual_threshold, Robustly estimate geometric transformation: >>> from skimage.transform import SimilarityTransform - >>> src = 100 * np.random.random((50, 2)) + >>> np.random.seed(0) + >>> src = 100 * np.random.rand(50, 2) >>> model0 = SimilarityTransform(scale=0.5, rotation=1, ... translation=(10, 20)) >>> dst = model0(src) diff --git a/skimage/measure/tests/test_structural_similarity.py b/skimage/measure/tests/test_structural_similarity.py index e08f2c31..35bbeeb8 100644 --- a/skimage/measure/tests/test_structural_similarity.py +++ b/skimage/measure/tests/test_structural_similarity.py @@ -9,8 +9,8 @@ np.random.seed(1234) def test_ssim_patch_range(): N = 51 - X = (np.random.random((N, N)) * 255).astype(np.uint8) - Y = (np.random.random((N, N)) * 255).astype(np.uint8) + X = (np.random.rand(N, N) * 255).astype(np.uint8) + Y = (np.random.rand(N, N) * 255).astype(np.uint8) assert(ssim(X, Y, win_size=N) < 0.1) assert_equal(ssim(X, X, win_size=N), 1) @@ -18,8 +18,8 @@ def test_ssim_patch_range(): def test_ssim_image(): N = 100 - X = (np.random.random((N, N)) * 255).astype(np.uint8) - Y = (np.random.random((N, N)) * 255).astype(np.uint8) + X = (np.random.rand(N, N) * 255).astype(np.uint8) + Y = (np.random.rand(N, N) * 255).astype(np.uint8) S0 = ssim(X, X, win_size=3) assert_equal(S0, 1) @@ -31,8 +31,8 @@ def test_ssim_image(): # NOTE: This test is known to randomly fail on some systems (Mac OS X 10.6) def test_ssim_grad(): N = 30 - X = np.random.random((N, N)) * 255 - Y = np.random.random((N, N)) * 255 + X = np.random.rand(N, N) * 255 + Y = np.random.rand(N, N) * 255 f = ssim(X, Y, dynamic_range=255) g = ssim(X, Y, dynamic_range=255, gradient=True) @@ -44,8 +44,8 @@ def test_ssim_grad(): def test_ssim_dtype(): N = 30 - X = np.random.random((N, N)) - Y = np.random.random((N, N)) + X = np.random.rand(N, N) + Y = np.random.rand(N, N) S1 = ssim(X, Y) diff --git a/skimage/morphology/tests/test_ccomp.py b/skimage/morphology/tests/test_ccomp.py index e934a5b7..fb596481 100644 --- a/skimage/morphology/tests/test_ccomp.py +++ b/skimage/morphology/tests/test_ccomp.py @@ -5,6 +5,9 @@ from skimage.morphology import label from warnings import catch_warnings from skimage._shared.utils import skimage_deprecation +np.random.seed(0) + + class TestConnectedComponents: def setup(self): self.x = np.array([[0, 0, 3, 2, 1, 9], @@ -24,7 +27,7 @@ class TestConnectedComponents: assert self.x[0, 2] == 3 def test_random(self): - x = (np.random.random((20, 30)) * 5).astype(np.int) + x = (np.random.rand(20, 30) * 5).astype(np.int) with catch_warnings(): labels = label(x) diff --git a/skimage/restoration/tests/test_denoise.py b/skimage/restoration/tests/test_denoise.py index d451aa74..c1091009 100644 --- a/skimage/restoration/tests/test_denoise.py +++ b/skimage/restoration/tests/test_denoise.py @@ -15,7 +15,7 @@ def test_denoise_tv_chambolle_2d(): # lena image img = lena_gray # add noise to lena - img += 0.5 * img.std() * np.random.random(img.shape) + img += 0.5 * img.std() * np.random.rand(*img.shape) # clip noise so that it does not exceed allowed range for float images. img = np.clip(img, 0, 1) # denoise @@ -57,7 +57,7 @@ def test_denoise_tv_chambolle_3d(): mask = (x - 22)**2 + (y - 20)**2 + (z - 17)**2 < 8**2 mask = 100 * mask.astype(np.float) mask += 60 - mask += 20 * np.random.random(mask.shape) + mask += 20 * np.random.rand(*mask.shape) mask[mask < 0] = 0 mask[mask > 255] = 255 res = restoration.denoise_tv_chambolle(mask.astype(np.uint8), weight=100) @@ -66,13 +66,13 @@ def test_denoise_tv_chambolle_3d(): # test wrong number of dimensions assert_raises(ValueError, restoration.denoise_tv_chambolle, - np.random.random((8, 8, 8, 8))) + np.random.rand(8, 8, 8, 8)) def test_denoise_tv_bregman_2d(): img = lena_gray # add some random noise - img += 0.5 * img.std() * np.random.random(img.shape) + img += 0.5 * img.std() * np.random.rand(*img.shape) img = np.clip(img, 0, 1) out1 = restoration.denoise_tv_bregman(img, weight=10) @@ -98,7 +98,7 @@ def test_denoise_tv_bregman_float_result_range(): def test_denoise_tv_bregman_3d(): img = lena # add some random noise - img += 0.5 * img.std() * np.random.random(img.shape) + img += 0.5 * img.std() * np.random.rand(*img.shape) img = np.clip(img, 0, 1) out1 = restoration.denoise_tv_bregman(img, weight=10) @@ -112,7 +112,7 @@ def test_denoise_tv_bregman_3d(): def test_denoise_bilateral_2d(): img = lena_gray # add some random noise - img += 0.5 * img.std() * np.random.random(img.shape) + img += 0.5 * img.std() * np.random.rand(*img.shape) img = np.clip(img, 0, 1) out1 = restoration.denoise_bilateral(img, sigma_range=0.1, @@ -128,7 +128,7 @@ def test_denoise_bilateral_2d(): def test_denoise_bilateral_3d(): img = lena # add some random noise - img += 0.5 * img.std() * np.random.random(img.shape) + img += 0.5 * img.std() * np.random.rand(*img.shape) img = np.clip(img, 0, 1) out1 = restoration.denoise_bilateral(img, sigma_range=0.1, diff --git a/skimage/segmentation/random_walker_segmentation.py b/skimage/segmentation/random_walker_segmentation.py index 731518e3..bcb57739 100644 --- a/skimage/segmentation/random_walker_segmentation.py +++ b/skimage/segmentation/random_walker_segmentation.py @@ -316,7 +316,8 @@ def random_walker(data, labels, beta=130, mode='bf', tol=1.e-3, copy=True, Examples -------- - >>> a = np.zeros((10, 10)) + 0.2 * np.random.random((10, 10)) + >>> np.random.seed(0) + >>> a = np.zeros((10, 10)) + 0.2 * np.random.rand(10, 10) >>> a[5:8, 5:8] += 1 >>> b = np.zeros_like(a) >>> b[3, 3] = 1 # Marker for first phase diff --git a/skimage/transform/tests/test_integral.py b/skimage/transform/tests/test_integral.py index 4a641e71..eb92a40b 100644 --- a/skimage/transform/tests/test_integral.py +++ b/skimage/transform/tests/test_integral.py @@ -3,14 +3,15 @@ from numpy.testing import assert_equal from skimage.transform import integral_image, integrate -x = (np.random.random((50, 50)) * 255).astype(np.uint8) +np.random.seed(0) +x = (np.random.rand(50, 50) * 255).astype(np.uint8) s = integral_image(x) def test_validity(): y = np.arange(12).reshape((4, 3)) - y = (np.random.random((50, 50)) * 255).astype(np.uint8) + y = (np.random.rand(50, 50) * 255).astype(np.uint8) assert_equal(integral_image(y)[-1, -1], y.sum()) diff --git a/skimage/transform/tests/test_warps.py b/skimage/transform/tests/test_warps.py index 07054ab7..5c210d9b 100644 --- a/skimage/transform/tests/test_warps.py +++ b/skimage/transform/tests/test_warps.py @@ -12,6 +12,9 @@ from skimage import transform as tf, data, img_as_float from skimage.color import rgb2gray +np.random.seed(0) + + def test_warp_tform(): x = np.zeros((5, 5), dtype=np.double) x[2, 2] = 1 @@ -249,7 +252,7 @@ def test_inverse(): def test_slow_warp_nonint_oshape(): - image = np.random.random((5, 5)) + image = np.random.rand(5, 5) assert_raises(ValueError, warp, image, lambda xy: xy, output_shape=(13.1, 19.5))