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