scikit-image

Форк
0
/
benchmark_filters.py 
151 строка · 4.4 Кб
1
# See "Writing benchmarks" in the asv docs for more information.
2
# https://asv.readthedocs.io/en/latest/writing_benchmarks.html
3
import numpy as np
4

5
from skimage import data, filters, color
6
from skimage.filters.thresholding import threshold_li
7

8

9
class FiltersSuite:
10
    """Benchmark for filter routines in scikit-image."""
11

12
    def setup(self):
13
        self.image = np.random.random((4000, 4000))
14
        self.image[:2000, :2000] += 1
15
        self.image[3000:, 3000] += 0.5
16

17
    def time_sobel(self):
18
        filters.sobel(self.image)
19

20

21
class FiltersSobel3D:
22
    """Benchmark for 3d sobel filters."""
23

24
    def setup(self):
25
        try:
26
            filters.sobel(np.ones((8, 8, 8)))
27
        except ValueError:
28
            raise NotImplementedError("3d sobel unavailable")
29
        self.image3d = data.binary_blobs(length=256, n_dim=3).astype(float)
30

31
    def time_sobel_3d(self):
32
        _ = filters.sobel(self.image3d)
33

34

35
class MultiOtsu:
36
    """Benchmarks for MultiOtsu threshold."""
37

38
    param_names = ['classes']
39
    params = [3, 4, 5]
40

41
    def setup(self, *args):
42
        self.image = data.camera()
43

44
    def time_threshold_multiotsu(self, classes):
45
        filters.threshold_multiotsu(self.image, classes=classes)
46

47
    def peakmem_reference(self, *args):
48
        """Provide reference for memory measurement with empty benchmark.
49

50
        Peakmem benchmarks measure the maximum amount of RAM used by a
51
        function. However, this maximum also includes the memory used
52
        during the setup routine (as of asv 0.2.1; see [1]_).
53
        Measuring an empty peakmem function might allow us to disambiguate
54
        between the memory used by setup and the memory used by target (see
55
        other ``peakmem_`` functions below).
56

57
        References
58
        ----------
59
        .. [1]: https://asv.readthedocs.io/en/stable/writing_benchmarks.html#peak-memory
60
        """
61
        pass
62

63
    def peakmem_threshold_multiotsu(self, classes):
64
        filters.threshold_multiotsu(self.image, classes=classes)
65

66

67
class ThresholdSauvolaSuite:
68
    """Benchmark for transform routines in scikit-image."""
69

70
    def setup(self):
71
        self.image = np.zeros((2000, 2000), dtype=np.uint8)
72
        self.image3D = np.zeros((30, 300, 300), dtype=np.uint8)
73

74
        idx = np.arange(500, 700)
75
        idx3D = np.arange(10, 200)
76

77
        self.image[idx[::-1], idx] = 255
78
        self.image[idx, idx] = 255
79

80
        self.image3D[:, idx3D[::-1], idx3D] = 255
81
        self.image3D[:, idx3D, idx3D] = 255
82

83
    def time_sauvola(self):
84
        filters.threshold_sauvola(self.image, window_size=51)
85

86
    def time_sauvola_3d(self):
87
        filters.threshold_sauvola(self.image3D, window_size=51)
88

89

90
class ThresholdLi:
91
    """Benchmark for threshold_li in scikit-image."""
92

93
    def setup(self):
94
        try:
95
            self.image = data.eagle()
96
        except ValueError:
97
            raise NotImplementedError("eagle data unavailable")
98
        self.image_float32 = self.image.astype(np.float32)
99

100
    def time_integer_image(self):
101
        threshold_li(self.image)
102

103
    def time_float32_image(self):
104
        threshold_li(self.image_float32)
105

106

107
class RidgeFilters:
108
    """Benchmark ridge filters in scikit-image."""
109

110
    def setup(self):
111
        # Ensure memory footprint of lazy import is included in reference
112
        self._ = filters.meijering, filters.sato, filters.frangi, filters.hessian
113
        self.image = color.rgb2gray(data.retina())
114

115
    def peakmem_setup(self):
116
        """peakmem includes the memory used by setup.
117
        Peakmem benchmarks measure the maximum amount of RAM used by a
118
        function. However, this maximum also includes the memory used
119
        by ``setup`` (as of asv 0.2.1; see [1]_)
120
        Measuring an empty peakmem function might allow us to disambiguate
121
        between the memory used by setup and the memory used by slic (see
122
        ``peakmem_slic_basic``, below).
123
        References
124
        ----------
125
        .. [1]: https://asv.readthedocs.io/en/stable/writing_benchmarks.html#peak-memory
126
        """
127
        pass
128

129
    def time_meijering(self):
130
        filters.meijering(self.image)
131

132
    def peakmem_meijering(self):
133
        filters.meijering(self.image)
134

135
    def time_sato(self):
136
        filters.sato(self.image)
137

138
    def peakmem_sato(self):
139
        filters.sato(self.image)
140

141
    def time_frangi(self):
142
        filters.frangi(self.image)
143

144
    def peakmem_frangi(self):
145
        filters.frangi(self.image)
146

147
    def time_hessian(self):
148
        filters.hessian(self.image)
149

150
    def peakmem_hessian(self):
151
        filters.hessian(self.image)
152

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

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

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

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