/
test_basic_features.py
62 lines (51 loc) · 2.11 KB
/
test_basic_features.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pytest
import numpy as np
from skimage.feature import multiscale_basic_features
@pytest.mark.parametrize('edges', (False, True))
@pytest.mark.parametrize('texture', (False, True))
def test_multiscale_basic_features_gray(edges, texture):
img = np.zeros((20, 20))
img[:10] = 1
img += 0.05 * np.random.randn(*img.shape)
features = multiscale_basic_features(img, edges=edges, texture=texture)
n_sigmas = 6
intensity = True
assert features.shape[-1] == (
n_sigmas * (int(intensity) + int(edges) + 2 * int(texture))
)
assert features.shape[:-1] == img.shape[:]
@pytest.mark.parametrize('edges', (False, True))
@pytest.mark.parametrize('texture', (False, True))
def test_multiscale_basic_features_rgb(edges, texture):
img = np.zeros((20, 20, 3))
img[:10] = 1
img += 0.05 * np.random.randn(*img.shape)
features = multiscale_basic_features(img, edges=edges, texture=texture,
channel_axis=-1)
n_sigmas = 6
intensity = True
assert features.shape[-1] == (
3 * n_sigmas * (int(intensity) + int(edges) + 2 * int(texture))
)
assert features.shape[:-1] == img.shape[:-1]
@pytest.mark.parametrize('channel_axis', [0, 1, 2, -1, -2])
def test_multiscale_basic_features_channel_axis(channel_axis):
num_channels = 5
shape_spatial = (10, 10)
ndim = len(shape_spatial)
shape = tuple(
np.insert(shape_spatial, channel_axis % (ndim + 1), num_channels)
)
img = np.zeros(shape)
img[:10] = 1
img += 0.05 * np.random.randn(*img.shape)
n_sigmas = 2
# features for all channels are concatenated along the last axis
features = multiscale_basic_features(img, sigma_min=1, sigma_max=2,
channel_axis=channel_axis)
assert features.shape[-1] == 5 * n_sigmas * 4
assert features.shape[:-1] == np.moveaxis(img, channel_axis, -1).shape[:-1]
# Consider channel_axis as spatial dimension
features = multiscale_basic_features(img, sigma_min=1, sigma_max=2)
assert features.shape[-1] == n_sigmas * 5
assert features.shape[:-1] == img.shape