scikit-image

Форк
0
/
test_basic_features.py 
62 строки · 2.0 Кб
1
import pytest
2
import numpy as np
3

4
from skimage.feature import multiscale_basic_features
5

6

7
@pytest.mark.parametrize('edges', (False, True))
8
@pytest.mark.parametrize('texture', (False, True))
9
def test_multiscale_basic_features_gray(edges, texture):
10
    img = np.zeros((20, 20))
11
    img[:10] = 1
12
    img += 0.05 * np.random.randn(*img.shape)
13
    features = multiscale_basic_features(img, edges=edges, texture=texture)
14

15
    n_sigmas = 6
16
    intensity = True
17
    assert features.shape[-1] == (
18
        n_sigmas * (int(intensity) + int(edges) + 2 * int(texture))
19
    )
20
    assert features.shape[:-1] == img.shape[:]
21

22

23
@pytest.mark.parametrize('edges', (False, True))
24
@pytest.mark.parametrize('texture', (False, True))
25
def test_multiscale_basic_features_rgb(edges, texture):
26
    img = np.zeros((20, 20, 3))
27
    img[:10] = 1
28
    img += 0.05 * np.random.randn(*img.shape)
29
    features = multiscale_basic_features(
30
        img, edges=edges, texture=texture, channel_axis=-1
31
    )
32

33
    n_sigmas = 6
34
    intensity = True
35
    assert features.shape[-1] == (
36
        3 * n_sigmas * (int(intensity) + int(edges) + 2 * int(texture))
37
    )
38
    assert features.shape[:-1] == img.shape[:-1]
39

40

41
@pytest.mark.parametrize('channel_axis', [0, 1, 2, -1, -2])
42
def test_multiscale_basic_features_channel_axis(channel_axis):
43
    num_channels = 5
44
    shape_spatial = (10, 10)
45
    ndim = len(shape_spatial)
46
    shape = tuple(np.insert(shape_spatial, channel_axis % (ndim + 1), num_channels))
47
    img = np.zeros(shape)
48
    img[:10] = 1
49
    img += 0.05 * np.random.randn(*img.shape)
50
    n_sigmas = 2
51

52
    # features for all channels are concatenated along the last axis
53
    features = multiscale_basic_features(
54
        img, sigma_min=1, sigma_max=2, channel_axis=channel_axis
55
    )
56
    assert features.shape[-1] == 5 * n_sigmas * 4
57
    assert features.shape[:-1] == np.moveaxis(img, channel_axis, -1).shape[:-1]
58

59
    # Consider channel_axis as spatial dimension
60
    features = multiscale_basic_features(img, sigma_min=1, sigma_max=2)
61
    assert features.shape[-1] == n_sigmas * 5
62
    assert features.shape[:-1] == img.shape
63

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.