mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-13 17:45:20 +08:00
Move away from random.random in favor of random.rand
This commit is contained in:
@@ -225,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
|
||||
@@ -351,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)
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ class BRIEF(DescriptorExtractor):
|
||||
[0, 0, 1, 1, 1, 1, 0, 0],
|
||||
[0, 0, 1, 1, 1, 1, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0]], dtype=int32)
|
||||
[0, 0, 0, 0, 0, 0, 0, 0]], dtype=np.int32)
|
||||
>>> square2 = np.zeros((9, 9), dtype=np.int32)
|
||||
>>> square2[2:7, 2:7] = 1
|
||||
>>> square2
|
||||
@@ -83,7 +83,7 @@ class BRIEF(DescriptorExtractor):
|
||||
[0, 0, 1, 1, 1, 1, 1, 0, 0],
|
||||
[0, 0, 1, 1, 1, 1, 1, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=int32)
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=np.int32)
|
||||
>>> keypoints1 = corner_peaks(corner_harris(square1), min_distance=1)
|
||||
>>> keypoints2 = corner_peaks(corner_harris(square2), min_distance=1)
|
||||
>>> extractor = BRIEF(patch_size=5)
|
||||
|
||||
@@ -10,8 +10,8 @@ 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))
|
||||
|
||||
|
||||
@@ -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)),
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -46,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)
|
||||
|
||||
@@ -60,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)
|
||||
|
||||
@@ -145,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)
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
'''
|
||||
|
||||
@@ -64,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
|
||||
@@ -93,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
|
||||
|
||||
@@ -68,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
|
||||
|
||||
@@ -126,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
|
||||
|
||||
@@ -8,10 +8,10 @@ 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):
|
||||
@@ -21,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:
|
||||
|
||||
@@ -88,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
|
||||
|
||||
@@ -51,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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -27,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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
@@ -331,7 +332,7 @@ def random_walker(data, labels, beta=130, mode='bf', tol=1.e-3, copy=True,
|
||||
[1, 1, 1, 1, 1, 2, 2, 2, 1, 1],
|
||||
[1, 1, 1, 1, 1, 2, 2, 2, 1, 1],
|
||||
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
|
||||
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], dtype=int32)
|
||||
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
|
||||
|
||||
"""
|
||||
# Parse input data
|
||||
|
||||
@@ -4,14 +4,14 @@ from numpy.testing import assert_equal
|
||||
from skimage.transform import integral_image, integrate
|
||||
|
||||
np.random.seed(0)
|
||||
x = (np.random.random((50, 50)) * 255).astype(np.uint8)
|
||||
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())
|
||||
|
||||
|
||||
@@ -252,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))
|
||||
|
||||
Reference in New Issue
Block a user