File: benchmark_peak_local_max.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 (36 lines) | stat: -rw-r--r-- 1,103 bytes parent folder | download | duplicates (2)
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
import inspect

import numpy as np

from scipy import ndimage as ndi
from skimage.feature import peak_local_max

# Inspect signature to automatically handle API changes across versions.
# `indices` currently defaults to True, but will be removed in the future.
peak_kwargs = {}
parameters = inspect.signature(peak_local_max).parameters
if 'indices' in parameters and parameters['indices'].default:
    peak_kwargs = {'indices': False}


class PeakLocalMaxSuite:
    def setup(self):
        mask = np.zeros([500, 500], dtype=bool)
        x, y = np.indices((500, 500))
        x_c = x // 20 * 20 + 10
        y_c = y // 20 * 20 + 10
        mask[(x - x_c) ** 2 + (y - y_c) ** 2 < 8**2] = True

        # create a mask, label each disk,
        self.labels, num_objs = ndi.label(mask)
        # create distance image for peak searching
        self.dist = ndi.distance_transform_edt(mask)

    def time_peak_local_max(self):
        peak_local_max(
            self.dist,
            labels=self.labels,
            min_distance=20,
            exclude_border=False,
            **peak_kwargs,
        )