update
This commit is contained in:
0
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/__init__.py
vendored
Normal file
0
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/__init__.py
vendored
Normal file
BIN
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/__pycache__/__init__.cpython-312.pyc
vendored
Normal file
BIN
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/__pycache__/__init__.cpython-312.pyc
vendored
Normal file
Binary file not shown.
BIN
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/__pycache__/test_draw.cpython-312.pyc
vendored
Normal file
BIN
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/__pycache__/test_draw.cpython-312.pyc
vendored
Normal file
Binary file not shown.
BIN
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/__pycache__/test_draw3d.cpython-312.pyc
vendored
Normal file
BIN
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/__pycache__/test_draw3d.cpython-312.pyc
vendored
Normal file
Binary file not shown.
BIN
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/__pycache__/test_draw_nd.cpython-312.pyc
vendored
Normal file
BIN
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/__pycache__/test_draw_nd.cpython-312.pyc
vendored
Normal file
Binary file not shown.
BIN
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/__pycache__/test_polygon2mask.cpython-312.pyc
vendored
Normal file
BIN
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/__pycache__/test_polygon2mask.cpython-312.pyc
vendored
Normal file
Binary file not shown.
BIN
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/__pycache__/test_random_shapes.cpython-312.pyc
vendored
Normal file
BIN
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/__pycache__/test_random_shapes.cpython-312.pyc
vendored
Normal file
Binary file not shown.
1261
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/test_draw.py
vendored
Normal file
1261
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/test_draw.py
vendored
Normal file
File diff suppressed because it is too large
Load Diff
219
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/test_draw3d.py
vendored
Normal file
219
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/test_draw3d.py
vendored
Normal file
@@ -0,0 +1,219 @@
|
||||
import numpy as np
|
||||
from skimage._shared.testing import assert_array_equal, assert_allclose
|
||||
|
||||
from skimage.draw import ellipsoid, ellipsoid_stats, rectangle
|
||||
from skimage._shared import testing
|
||||
|
||||
|
||||
def test_ellipsoid_sign_parameters1():
|
||||
with testing.raises(ValueError):
|
||||
ellipsoid(-1, 2, 2)
|
||||
|
||||
|
||||
def test_ellipsoid_sign_parameters2():
|
||||
with testing.raises(ValueError):
|
||||
ellipsoid(0, 2, 2)
|
||||
|
||||
|
||||
def test_ellipsoid_sign_parameters3():
|
||||
with testing.raises(ValueError):
|
||||
ellipsoid(-3, -2, 2)
|
||||
|
||||
|
||||
def test_ellipsoid_bool():
|
||||
test = ellipsoid(2, 2, 2)[1:-1, 1:-1, 1:-1]
|
||||
test_anisotropic = ellipsoid(2, 2, 4, spacing=(1.0, 1.0, 2.0))
|
||||
test_anisotropic = test_anisotropic[1:-1, 1:-1, 1:-1]
|
||||
|
||||
expected = np.array(
|
||||
[
|
||||
[
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 1, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
],
|
||||
[
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 1, 1, 1, 0],
|
||||
[0, 1, 1, 1, 0],
|
||||
[0, 1, 1, 1, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
],
|
||||
[
|
||||
[0, 0, 1, 0, 0],
|
||||
[0, 1, 1, 1, 0],
|
||||
[1, 1, 1, 1, 1],
|
||||
[0, 1, 1, 1, 0],
|
||||
[0, 0, 1, 0, 0],
|
||||
],
|
||||
[
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 1, 1, 1, 0],
|
||||
[0, 1, 1, 1, 0],
|
||||
[0, 1, 1, 1, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
],
|
||||
[
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 1, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
],
|
||||
]
|
||||
)
|
||||
|
||||
assert_array_equal(test, expected.astype(bool))
|
||||
assert_array_equal(test_anisotropic, expected.astype(bool))
|
||||
|
||||
|
||||
def test_ellipsoid_levelset():
|
||||
test = ellipsoid(2, 2, 2, levelset=True)[1:-1, 1:-1, 1:-1]
|
||||
test_anisotropic = ellipsoid(2, 2, 4, spacing=(1.0, 1.0, 2.0), levelset=True)
|
||||
test_anisotropic = test_anisotropic[1:-1, 1:-1, 1:-1]
|
||||
|
||||
expected = np.array(
|
||||
[
|
||||
[
|
||||
[2.0, 1.25, 1.0, 1.25, 2.0],
|
||||
[1.25, 0.5, 0.25, 0.5, 1.25],
|
||||
[1.0, 0.25, 0.0, 0.25, 1.0],
|
||||
[1.25, 0.5, 0.25, 0.5, 1.25],
|
||||
[2.0, 1.25, 1.0, 1.25, 2.0],
|
||||
],
|
||||
[
|
||||
[1.25, 0.5, 0.25, 0.5, 1.25],
|
||||
[0.5, -0.25, -0.5, -0.25, 0.5],
|
||||
[0.25, -0.5, -0.75, -0.5, 0.25],
|
||||
[0.5, -0.25, -0.5, -0.25, 0.5],
|
||||
[1.25, 0.5, 0.25, 0.5, 1.25],
|
||||
],
|
||||
[
|
||||
[1.0, 0.25, 0.0, 0.25, 1.0],
|
||||
[0.25, -0.5, -0.75, -0.5, 0.25],
|
||||
[0.0, -0.75, -1.0, -0.75, 0.0],
|
||||
[0.25, -0.5, -0.75, -0.5, 0.25],
|
||||
[1.0, 0.25, 0.0, 0.25, 1.0],
|
||||
],
|
||||
[
|
||||
[1.25, 0.5, 0.25, 0.5, 1.25],
|
||||
[0.5, -0.25, -0.5, -0.25, 0.5],
|
||||
[0.25, -0.5, -0.75, -0.5, 0.25],
|
||||
[0.5, -0.25, -0.5, -0.25, 0.5],
|
||||
[1.25, 0.5, 0.25, 0.5, 1.25],
|
||||
],
|
||||
[
|
||||
[2.0, 1.25, 1.0, 1.25, 2.0],
|
||||
[1.25, 0.5, 0.25, 0.5, 1.25],
|
||||
[1.0, 0.25, 0.0, 0.25, 1.0],
|
||||
[1.25, 0.5, 0.25, 0.5, 1.25],
|
||||
[2.0, 1.25, 1.0, 1.25, 2.0],
|
||||
],
|
||||
]
|
||||
)
|
||||
|
||||
assert_allclose(test, expected)
|
||||
assert_allclose(test_anisotropic, expected)
|
||||
|
||||
|
||||
def test_ellipsoid_stats():
|
||||
# Test comparison values generated by Wolfram Alpha
|
||||
vol, surf = ellipsoid_stats(6, 10, 16)
|
||||
assert_allclose(1280 * np.pi, vol, atol=1e-4)
|
||||
assert_allclose(1383.28, surf, atol=1e-2)
|
||||
|
||||
# Test when a <= b <= c does not hold
|
||||
vol, surf = ellipsoid_stats(16, 6, 10)
|
||||
assert_allclose(1280 * np.pi, vol, atol=1e-4)
|
||||
assert_allclose(1383.28, surf, atol=1e-2)
|
||||
|
||||
# Larger test to ensure reliability over broad range
|
||||
vol, surf = ellipsoid_stats(17, 27, 169)
|
||||
assert_allclose(103428 * np.pi, vol, atol=1e-4)
|
||||
assert_allclose(37426.3, surf, atol=1e-1)
|
||||
|
||||
|
||||
def test_rect_3d_extent():
|
||||
expected = np.array(
|
||||
[
|
||||
[
|
||||
[0, 0, 1, 1, 1],
|
||||
[0, 0, 1, 1, 1],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
],
|
||||
[
|
||||
[0, 0, 1, 1, 1],
|
||||
[0, 0, 1, 1, 1],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
],
|
||||
[
|
||||
[0, 0, 1, 1, 1],
|
||||
[0, 0, 1, 1, 1],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
],
|
||||
[
|
||||
[0, 0, 1, 1, 1],
|
||||
[0, 0, 1, 1, 1],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
],
|
||||
],
|
||||
dtype=np.uint8,
|
||||
)
|
||||
img = np.zeros((4, 5, 5), dtype=np.uint8)
|
||||
start = (0, 0, 2)
|
||||
extent = (5, 2, 3)
|
||||
pp, rr, cc = rectangle(start, extent=extent, shape=img.shape)
|
||||
img[pp, rr, cc] = 1
|
||||
assert_array_equal(img, expected)
|
||||
|
||||
|
||||
def test_rect_3d_end():
|
||||
expected = np.array(
|
||||
[
|
||||
[
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
],
|
||||
[
|
||||
[0, 0, 1, 1, 0],
|
||||
[0, 0, 1, 1, 0],
|
||||
[0, 0, 1, 1, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
],
|
||||
[
|
||||
[0, 0, 1, 1, 0],
|
||||
[0, 0, 1, 1, 0],
|
||||
[0, 0, 1, 1, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
],
|
||||
[
|
||||
[0, 0, 1, 1, 0],
|
||||
[0, 0, 1, 1, 0],
|
||||
[0, 0, 1, 1, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0],
|
||||
],
|
||||
],
|
||||
dtype=np.uint8,
|
||||
)
|
||||
img = np.zeros((4, 5, 5), dtype=np.uint8)
|
||||
start = (1, 0, 2)
|
||||
end = (3, 2, 3)
|
||||
pp, rr, cc = rectangle(start, end=end, shape=img.shape)
|
||||
img[pp, rr, cc] = 1
|
||||
assert_array_equal(img, expected)
|
||||
18
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/test_draw_nd.py
vendored
Normal file
18
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/test_draw_nd.py
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
from skimage.draw import line_nd
|
||||
from skimage._shared.testing import assert_equal
|
||||
|
||||
|
||||
def test_empty_line():
|
||||
coords = line_nd((1, 1, 1), (1, 1, 1))
|
||||
assert len(coords) == 3
|
||||
assert all(len(c) == 0 for c in coords)
|
||||
|
||||
|
||||
def test_zero_line():
|
||||
coords = line_nd((-1, -1), (2, 2))
|
||||
assert_equal(coords, [[-1, 0, 1], [-1, 0, 1]])
|
||||
|
||||
|
||||
def test_no_round():
|
||||
coords = line_nd((0.5, 0), (2.5, 0), integer=False, endpoint=True)
|
||||
assert_equal(coords, [[0.5, 1.5, 2.5], [0, 0, 0]])
|
||||
15
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/test_polygon2mask.py
vendored
Normal file
15
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/test_polygon2mask.py
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import numpy as np
|
||||
|
||||
from skimage import draw
|
||||
|
||||
|
||||
image_shape = (512, 512)
|
||||
polygon = np.array(
|
||||
[[80, 111, 146, 234, 407, 300, 187, 45], [465, 438, 499, 380, 450, 287, 210, 167]]
|
||||
).T
|
||||
|
||||
|
||||
def test_polygon2mask():
|
||||
mask = draw.polygon2mask(image_shape, polygon)
|
||||
assert mask.shape == image_shape
|
||||
assert mask.sum() == 57653
|
||||
178
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/test_random_shapes.py
vendored
Normal file
178
.CondaPkg/env/Lib/site-packages/skimage/draw/tests/test_random_shapes.py
vendored
Normal file
@@ -0,0 +1,178 @@
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from skimage._shared import testing
|
||||
from skimage._shared._warnings import expected_warnings
|
||||
from skimage.draw import random_shapes
|
||||
|
||||
|
||||
def test_generates_color_images_with_correct_shape():
|
||||
image, _ = random_shapes((128, 128), max_shapes=10)
|
||||
assert image.shape == (128, 128, 3)
|
||||
|
||||
|
||||
def test_generates_gray_images_with_correct_shape():
|
||||
image, _ = random_shapes(
|
||||
(4567, 123), min_shapes=3, max_shapes=20, channel_axis=None
|
||||
)
|
||||
assert image.shape == (4567, 123)
|
||||
|
||||
|
||||
def test_generates_gray_images_with_correct_shape_deprecated_multichannel():
|
||||
image, _ = random_shapes(
|
||||
(4567, 123), min_shapes=3, max_shapes=20, channel_axis=None
|
||||
)
|
||||
assert image.shape == (4567, 123)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('channel_axis', [None, 0, 1, 2])
|
||||
def test_generated_shape_for_channel_axis(channel_axis):
|
||||
shape = (128, 64)
|
||||
num_channels = 5
|
||||
|
||||
image, _ = random_shapes(
|
||||
shape,
|
||||
num_channels=num_channels,
|
||||
min_shapes=3,
|
||||
max_shapes=10,
|
||||
channel_axis=channel_axis,
|
||||
)
|
||||
|
||||
if channel_axis is None:
|
||||
expected_shape = shape
|
||||
else:
|
||||
expected_shape = tuple(np.insert(shape, channel_axis, num_channels))
|
||||
|
||||
assert image.shape == expected_shape
|
||||
|
||||
|
||||
def test_generates_correct_bounding_boxes_for_rectangles():
|
||||
image, labels = random_shapes((128, 128), max_shapes=1, shape='rectangle', rng=42)
|
||||
|
||||
assert len(labels) == 1
|
||||
label, bbox = labels[0]
|
||||
assert label == 'rectangle', label
|
||||
|
||||
crop = image[bbox[0][0] : bbox[0][1], bbox[1][0] : bbox[1][1]]
|
||||
|
||||
# The crop is filled.
|
||||
assert (crop >= 0).all() and (crop < 255).all()
|
||||
|
||||
# The crop is complete.
|
||||
image[bbox[0][0] : bbox[0][1], bbox[1][0] : bbox[1][1]] = 255
|
||||
assert (image == 255).all()
|
||||
|
||||
|
||||
def test_generates_correct_bounding_boxes_for_triangles():
|
||||
image, labels = random_shapes((128, 128), max_shapes=1, shape='triangle', rng=42)
|
||||
assert len(labels) == 1
|
||||
label, bbox = labels[0]
|
||||
assert label == 'triangle', label
|
||||
|
||||
crop = image[bbox[0][0] : bbox[0][1], bbox[1][0] : bbox[1][1]]
|
||||
|
||||
# The crop is filled.
|
||||
assert (crop >= 0).any() and (crop < 255).any()
|
||||
|
||||
# The crop is complete.
|
||||
image[bbox[0][0] : bbox[0][1], bbox[1][0] : bbox[1][1]] = 255
|
||||
assert (image == 255).all()
|
||||
|
||||
|
||||
def test_generates_correct_bounding_boxes_for_circles():
|
||||
image, labels = random_shapes(
|
||||
(43, 44), max_shapes=1, min_size=20, max_size=20, shape='circle', rng=42
|
||||
)
|
||||
assert len(labels) == 1
|
||||
label, bbox = labels[0]
|
||||
assert label == 'circle', label
|
||||
|
||||
crop = image[bbox[0][0] : bbox[0][1], bbox[1][0] : bbox[1][1]]
|
||||
|
||||
# The crop is filled.
|
||||
assert (crop >= 0).any() and (crop < 255).any()
|
||||
|
||||
# The crop is complete.
|
||||
image[bbox[0][0] : bbox[0][1], bbox[1][0] : bbox[1][1]] = 255
|
||||
assert (image == 255).all()
|
||||
|
||||
|
||||
def test_generates_correct_bounding_boxes_for_ellipses():
|
||||
image, labels = random_shapes(
|
||||
(43, 44), max_shapes=1, min_size=20, max_size=20, shape='ellipse', rng=42
|
||||
)
|
||||
assert len(labels) == 1
|
||||
label, bbox = labels[0]
|
||||
assert label == 'ellipse', label
|
||||
|
||||
crop = image[bbox[0][0] : bbox[0][1], bbox[1][0] : bbox[1][1]]
|
||||
|
||||
# The crop is filled.
|
||||
assert (crop >= 0).any() and (crop < 255).any()
|
||||
|
||||
# The crop is complete.
|
||||
image[bbox[0][0] : bbox[0][1], bbox[1][0] : bbox[1][1]] = 255
|
||||
assert (image == 255).all()
|
||||
|
||||
|
||||
def test_generate_circle_throws_when_size_too_small():
|
||||
with testing.raises(ValueError):
|
||||
random_shapes((64, 128), max_shapes=1, min_size=1, max_size=1, shape='circle')
|
||||
|
||||
|
||||
def test_generate_ellipse_throws_when_size_too_small():
|
||||
with testing.raises(ValueError):
|
||||
random_shapes((64, 128), max_shapes=1, min_size=1, max_size=1, shape='ellipse')
|
||||
|
||||
|
||||
def test_generate_triangle_throws_when_size_too_small():
|
||||
with testing.raises(ValueError):
|
||||
random_shapes((128, 64), max_shapes=1, min_size=1, max_size=1, shape='triangle')
|
||||
|
||||
|
||||
def test_can_generate_one_by_one_rectangle():
|
||||
image, labels = random_shapes(
|
||||
(50, 128), max_shapes=1, min_size=1, max_size=1, shape='rectangle'
|
||||
)
|
||||
assert len(labels) == 1
|
||||
_, bbox = labels[0]
|
||||
crop = image[bbox[0][0] : bbox[0][1], bbox[1][0] : bbox[1][1]]
|
||||
|
||||
# rgb
|
||||
assert np.shape(crop) == (1, 1, 3) and np.any(crop >= 1) and np.any(crop < 255)
|
||||
|
||||
|
||||
def test_throws_when_intensity_range_out_of_range():
|
||||
with testing.raises(ValueError):
|
||||
random_shapes(
|
||||
(1000, 1234), max_shapes=1, channel_axis=None, intensity_range=(0, 256)
|
||||
)
|
||||
with testing.raises(ValueError):
|
||||
random_shapes((2, 2), max_shapes=1, intensity_range=((-1, 255),))
|
||||
|
||||
|
||||
def test_returns_empty_labels_and_white_image_when_cannot_fit_shape():
|
||||
# The circle will never fit this.
|
||||
with expected_warnings(['Could not fit']):
|
||||
image, labels = random_shapes(
|
||||
(10000, 10000), max_shapes=1, min_size=10000, shape='circle'
|
||||
)
|
||||
assert len(labels) == 0
|
||||
assert (image == 255).all()
|
||||
|
||||
|
||||
def test_random_shapes_is_reproducible_with_seed():
|
||||
random_seed = 42
|
||||
labels = []
|
||||
for _ in range(5):
|
||||
_, label = random_shapes((128, 128), max_shapes=5, rng=random_seed)
|
||||
labels.append(label)
|
||||
assert all(other == labels[0] for other in labels[1:])
|
||||
|
||||
|
||||
def test_generates_white_image_when_intensity_range_255():
|
||||
image, labels = random_shapes(
|
||||
(128, 128), max_shapes=3, intensity_range=((255, 255),), rng=42
|
||||
)
|
||||
assert len(labels) > 0
|
||||
assert (image == 255).all()
|
||||
Reference in New Issue
Block a user