File: benchmark_rank.py

package info (click to toggle)
skimage 0.26.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 32,720 kB
  • sloc: python: 61,600; cpp: 2,592; ansic: 1,591; xml: 1,342; javascript: 1,267; makefile: 135; sh: 16
file content (29 lines) | stat: -rw-r--r-- 1,019 bytes parent folder | download | duplicates (4)
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
import numpy as np
from skimage.filters import rank
from skimage.filters.rank import __all__ as all_rank_filters
from skimage.filters.rank import __3Dfilters as all_3d_rank_filters
from skimage.morphology import disk, ball


class RankSuite:
    param_names = ["filter_func", "shape"]
    params = [sorted(all_rank_filters), [(32, 32), (256, 256)]]

    def setup(self, filter_func, shape):
        self.image = np.random.randint(0, 255, size=shape, dtype=np.uint8)
        self.footprint = disk(1)

    def time_filter(self, filter_func, shape):
        getattr(rank, filter_func)(self.image, self.footprint)


class Rank3DSuite:
    param_names = ["filter3d", "shape3d"]
    params = [sorted(all_3d_rank_filters), [(32, 32, 32), (128, 128, 128)]]

    def setup(self, filter3d, shape3d):
        self.volume = np.random.randint(0, 255, size=shape3d, dtype=np.uint8)
        self.footprint_3d = ball(1)

    def time_3d_filters(self, filter3d, shape3d):
        getattr(rank, filter3d)(self.volume, self.footprint_3d)