scikit-image

Форк
0
646 строк · 21.5 Кб
1
import itertools
2

3
import numpy as np
4
import pytest
5
from numpy.testing import assert_array_almost_equal, assert_array_equal, assert_equal
6
from scipy import ndimage as ndi
7

8
from skimage._shared._warnings import expected_warnings
9
from skimage.feature import peak
10

11

12
np.random.seed(21)
13

14

15
class TestPeakLocalMax:
16
    def test_trivial_case(self):
17
        trivial = np.zeros((25, 25))
18
        peak_indices = peak.peak_local_max(trivial, min_distance=1)
19
        assert type(peak_indices) is np.ndarray
20
        assert peak_indices.size == 0
21

22
    def test_noisy_peaks(self):
23
        peak_locations = [(7, 7), (7, 13), (13, 7), (13, 13)]
24

25
        # image with noise of amplitude 0.8 and peaks of amplitude 1
26
        image = 0.8 * np.random.rand(20, 20)
27
        for r, c in peak_locations:
28
            image[r, c] = 1
29

30
        peaks_detected = peak.peak_local_max(image, min_distance=5)
31

32
        assert len(peaks_detected) == len(peak_locations)
33
        for loc in peaks_detected:
34
            assert tuple(loc) in peak_locations
35

36
    def test_relative_threshold(self):
37
        image = np.zeros((5, 5), dtype=np.uint8)
38
        image[1, 1] = 10
39
        image[3, 3] = 20
40
        peaks = peak.peak_local_max(image, min_distance=1, threshold_rel=0.5)
41
        assert len(peaks) == 1
42
        assert_array_almost_equal(peaks, [(3, 3)])
43

44
    def test_absolute_threshold(self):
45
        image = np.zeros((5, 5), dtype=np.uint8)
46
        image[1, 1] = 10
47
        image[3, 3] = 20
48
        peaks = peak.peak_local_max(image, min_distance=1, threshold_abs=10)
49
        assert len(peaks) == 1
50
        assert_array_almost_equal(peaks, [(3, 3)])
51

52
    def test_constant_image(self):
53
        image = np.full((20, 20), 128, dtype=np.uint8)
54
        peaks = peak.peak_local_max(image, min_distance=1)
55
        assert len(peaks) == 0
56

57
    def test_flat_peak(self):
58
        image = np.zeros((5, 5), dtype=np.uint8)
59
        image[1:3, 1:3] = 10
60
        peaks = peak.peak_local_max(image, min_distance=1)
61
        assert len(peaks) == 4
62

63
    def test_sorted_peaks(self):
64
        image = np.zeros((5, 5), dtype=np.uint8)
65
        image[1, 1] = 20
66
        image[3, 3] = 10
67
        peaks = peak.peak_local_max(image, min_distance=1)
68
        assert peaks.tolist() == [[1, 1], [3, 3]]
69

70
        image = np.zeros((3, 10))
71
        image[1, (1, 3, 5, 7)] = (1, 2, 3, 4)
72
        peaks = peak.peak_local_max(image, min_distance=1)
73
        assert peaks.tolist() == [[1, 7], [1, 5], [1, 3], [1, 1]]
74

75
    def test_num_peaks(self):
76
        image = np.zeros((7, 7), dtype=np.uint8)
77
        image[1, 1] = 10
78
        image[1, 3] = 11
79
        image[1, 5] = 12
80
        image[3, 5] = 8
81
        image[5, 3] = 7
82
        assert len(peak.peak_local_max(image, min_distance=1, threshold_abs=0)) == 5
83
        peaks_limited = peak.peak_local_max(
84
            image, min_distance=1, threshold_abs=0, num_peaks=2
85
        )
86
        assert len(peaks_limited) == 2
87
        assert (1, 3) in peaks_limited
88
        assert (1, 5) in peaks_limited
89
        peaks_limited = peak.peak_local_max(
90
            image, min_distance=1, threshold_abs=0, num_peaks=4
91
        )
92
        assert len(peaks_limited) == 4
93
        assert (1, 3) in peaks_limited
94
        assert (1, 5) in peaks_limited
95
        assert (1, 1) in peaks_limited
96
        assert (3, 5) in peaks_limited
97

98
    def test_num_peaks_and_labels(self):
99
        image = np.zeros((7, 7), dtype=np.uint8)
100
        labels = np.zeros((7, 7), dtype=np.uint8) + 20
101
        image[1, 1] = 10
102
        image[1, 3] = 11
103
        image[1, 5] = 12
104
        image[3, 5] = 8
105
        image[5, 3] = 7
106
        peaks_limited = peak.peak_local_max(
107
            image, min_distance=1, threshold_abs=0, labels=labels
108
        )
109
        assert len(peaks_limited) == 5
110
        peaks_limited = peak.peak_local_max(
111
            image, min_distance=1, threshold_abs=0, labels=labels, num_peaks=2
112
        )
113
        assert len(peaks_limited) == 2
114

115
    def test_num_peaks_tot_vs_labels_4quadrants(self):
116
        np.random.seed(21)
117
        image = np.random.uniform(size=(20, 30))
118
        i, j = np.mgrid[0:20, 0:30]
119
        labels = 1 + (i >= 10) + (j >= 15) * 2
120
        result = peak.peak_local_max(
121
            image,
122
            labels=labels,
123
            min_distance=1,
124
            threshold_rel=0,
125
            num_peaks=np.inf,
126
            num_peaks_per_label=2,
127
        )
128
        assert len(result) == 8
129
        result = peak.peak_local_max(
130
            image,
131
            labels=labels,
132
            min_distance=1,
133
            threshold_rel=0,
134
            num_peaks=np.inf,
135
            num_peaks_per_label=1,
136
        )
137
        assert len(result) == 4
138
        result = peak.peak_local_max(
139
            image,
140
            labels=labels,
141
            min_distance=1,
142
            threshold_rel=0,
143
            num_peaks=2,
144
            num_peaks_per_label=2,
145
        )
146
        assert len(result) == 2
147

148
    def test_num_peaks3D(self):
149
        # Issue 1354: the old code only hold for 2D arrays
150
        # and this code would die with IndexError
151
        image = np.zeros((10, 10, 100))
152
        image[5, 5, ::5] = np.arange(20)
153
        peaks_limited = peak.peak_local_max(image, min_distance=1, num_peaks=2)
154
        assert len(peaks_limited) == 2
155

156
    def test_reorder_labels(self):
157
        image = np.random.uniform(size=(40, 60))
158
        i, j = np.mgrid[0:40, 0:60]
159
        labels = 1 + (i >= 20) + (j >= 30) * 2
160
        labels[labels == 4] = 5
161
        i, j = np.mgrid[-3:4, -3:4]
162
        footprint = i * i + j * j <= 9
163
        expected = np.zeros(image.shape, float)
164
        for imin, imax in ((0, 20), (20, 40)):
165
            for jmin, jmax in ((0, 30), (30, 60)):
166
                expected[imin:imax, jmin:jmax] = ndi.maximum_filter(
167
                    image[imin:imax, jmin:jmax], footprint=footprint
168
                )
169
        expected = expected == image
170
        peak_idx = peak.peak_local_max(
171
            image,
172
            labels=labels,
173
            min_distance=1,
174
            threshold_rel=0,
175
            footprint=footprint,
176
            exclude_border=False,
177
        )
178
        result = np.zeros_like(expected, dtype=bool)
179
        result[tuple(peak_idx.T)] = True
180
        assert (result == expected).all()
181

182
    def test_indices_with_labels(self):
183
        image = np.random.uniform(size=(40, 60))
184
        i, j = np.mgrid[0:40, 0:60]
185
        labels = 1 + (i >= 20) + (j >= 30) * 2
186
        i, j = np.mgrid[-3:4, -3:4]
187
        footprint = i * i + j * j <= 9
188
        expected = np.zeros(image.shape, float)
189
        for imin, imax in ((0, 20), (20, 40)):
190
            for jmin, jmax in ((0, 30), (30, 60)):
191
                expected[imin:imax, jmin:jmax] = ndi.maximum_filter(
192
                    image[imin:imax, jmin:jmax], footprint=footprint
193
                )
194
        expected = np.stack(np.nonzero(expected == image), axis=-1)
195
        expected = expected[np.argsort(image[tuple(expected.T)])[::-1]]
196
        result = peak.peak_local_max(
197
            image,
198
            labels=labels,
199
            min_distance=1,
200
            threshold_rel=0,
201
            footprint=footprint,
202
            exclude_border=False,
203
        )
204
        result = result[np.argsort(image[tuple(result.T)])[::-1]]
205
        assert (result == expected).all()
206

207
    def test_ndarray_exclude_border(self):
208
        nd_image = np.zeros((5, 5, 5))
209
        nd_image[[1, 0, 0], [0, 1, 0], [0, 0, 1]] = 1
210
        nd_image[3, 0, 0] = 1
211
        nd_image[2, 2, 2] = 1
212
        expected = np.array([[2, 2, 2]], dtype=int)
213
        expectedNoBorder = np.array([[0, 0, 1], [2, 2, 2], [3, 0, 0]], dtype=int)
214
        result = peak.peak_local_max(nd_image, min_distance=2, exclude_border=2)
215
        assert_array_equal(result, expected)
216
        # Check that bools work as expected
217
        assert_array_equal(
218
            peak.peak_local_max(nd_image, min_distance=2, exclude_border=2),
219
            peak.peak_local_max(nd_image, min_distance=2, exclude_border=True),
220
        )
221
        assert_array_equal(
222
            peak.peak_local_max(nd_image, min_distance=2, exclude_border=0),
223
            peak.peak_local_max(nd_image, min_distance=2, exclude_border=False),
224
        )
225

226
        # Check both versions with no border
227
        result = peak.peak_local_max(nd_image, min_distance=2, exclude_border=0)
228
        assert_array_equal(result, expectedNoBorder)
229
        peak_idx = peak.peak_local_max(nd_image, exclude_border=False)
230
        result = np.zeros_like(nd_image, dtype=bool)
231
        result[tuple(peak_idx.T)] = True
232
        assert_array_equal(result, nd_image.astype(bool))
233

234
    def test_empty(self):
235
        image = np.zeros((10, 20))
236
        labels = np.zeros((10, 20), int)
237
        result = peak.peak_local_max(
238
            image,
239
            labels=labels,
240
            footprint=np.ones((3, 3), bool),
241
            min_distance=1,
242
            threshold_rel=0,
243
            exclude_border=False,
244
        )
245
        assert result.shape == (0, image.ndim)
246

247
    def test_empty_non2d_indices(self):
248
        image = np.zeros((10, 10, 10))
249
        result = peak.peak_local_max(
250
            image,
251
            footprint=np.ones((3, 3, 3), bool),
252
            min_distance=1,
253
            threshold_rel=0,
254
            exclude_border=False,
255
        )
256
        assert result.shape == (0, image.ndim)
257

258
    def test_one_point(self):
259
        image = np.zeros((10, 20))
260
        labels = np.zeros((10, 20), int)
261
        image[5, 5] = 1
262
        labels[5, 5] = 1
263
        peak_idx = peak.peak_local_max(
264
            image,
265
            labels=labels,
266
            footprint=np.ones((3, 3), bool),
267
            min_distance=1,
268
            threshold_rel=0,
269
            exclude_border=False,
270
        )
271
        result = np.zeros_like(image, dtype=bool)
272
        result[tuple(peak_idx.T)] = True
273
        assert np.all(result == (labels == 1))
274

275
    def test_adjacent_and_same(self):
276
        image = np.zeros((10, 20))
277
        labels = np.zeros((10, 20), int)
278
        image[5, 5:6] = 1
279
        labels[5, 5:6] = 1
280
        expected = np.stack(np.where(labels == 1), axis=-1)
281
        result = peak.peak_local_max(
282
            image,
283
            labels=labels,
284
            footprint=np.ones((3, 3), bool),
285
            min_distance=1,
286
            threshold_rel=0,
287
            exclude_border=False,
288
        )
289
        assert_array_equal(result, expected)
290

291
    def test_adjacent_and_different(self):
292
        image = np.zeros((10, 20))
293
        labels = np.zeros((10, 20), int)
294
        image[5, 5] = 1
295
        image[5, 6] = 0.5
296
        labels[5, 5:6] = 1
297
        expected = np.stack(np.where(image == 1), axis=-1)
298
        result = peak.peak_local_max(
299
            image,
300
            labels=labels,
301
            footprint=np.ones((3, 3), bool),
302
            min_distance=1,
303
            threshold_rel=0,
304
            exclude_border=False,
305
        )
306
        assert_array_equal(result, expected)
307
        result = peak.peak_local_max(
308
            image, labels=labels, min_distance=1, threshold_rel=0, exclude_border=False
309
        )
310
        assert_array_equal(result, expected)
311

312
    def test_not_adjacent_and_different(self):
313
        image = np.zeros((10, 20))
314
        labels = np.zeros((10, 20), int)
315
        image[5, 5] = 1
316
        image[5, 8] = 0.5
317
        labels[image > 0] = 1
318
        expected = np.stack(np.where(labels == 1), axis=-1)
319
        result = peak.peak_local_max(
320
            image,
321
            labels=labels,
322
            footprint=np.ones((3, 3), bool),
323
            min_distance=1,
324
            threshold_rel=0,
325
            exclude_border=False,
326
        )
327
        assert_array_equal(result, expected)
328

329
    def test_two_objects(self):
330
        image = np.zeros((10, 20))
331
        labels = np.zeros((10, 20), int)
332
        image[5, 5] = 1
333
        image[5, 15] = 0.5
334
        labels[5, 5] = 1
335
        labels[5, 15] = 2
336
        expected = np.stack(np.where(labels > 0), axis=-1)
337
        result = peak.peak_local_max(
338
            image,
339
            labels=labels,
340
            footprint=np.ones((3, 3), bool),
341
            min_distance=1,
342
            threshold_rel=0,
343
            exclude_border=False,
344
        )
345
        assert_array_equal(result, expected)
346

347
    def test_adjacent_different_objects(self):
348
        image = np.zeros((10, 20))
349
        labels = np.zeros((10, 20), int)
350
        image[5, 5] = 1
351
        image[5, 6] = 0.5
352
        labels[5, 5] = 1
353
        labels[5, 6] = 2
354
        expected = np.stack(np.where(labels > 0), axis=-1)
355
        result = peak.peak_local_max(
356
            image,
357
            labels=labels,
358
            footprint=np.ones((3, 3), bool),
359
            min_distance=1,
360
            threshold_rel=0,
361
            exclude_border=False,
362
        )
363
        assert_array_equal(result, expected)
364

365
    def test_four_quadrants(self):
366
        image = np.random.uniform(size=(20, 30))
367
        i, j = np.mgrid[0:20, 0:30]
368
        labels = 1 + (i >= 10) + (j >= 15) * 2
369
        i, j = np.mgrid[-3:4, -3:4]
370
        footprint = i * i + j * j <= 9
371
        expected = np.zeros(image.shape, float)
372
        for imin, imax in ((0, 10), (10, 20)):
373
            for jmin, jmax in ((0, 15), (15, 30)):
374
                expected[imin:imax, jmin:jmax] = ndi.maximum_filter(
375
                    image[imin:imax, jmin:jmax], footprint=footprint
376
                )
377
        expected = expected == image
378
        peak_idx = peak.peak_local_max(
379
            image,
380
            labels=labels,
381
            footprint=footprint,
382
            min_distance=1,
383
            threshold_rel=0,
384
            exclude_border=False,
385
        )
386
        result = np.zeros_like(image, dtype=bool)
387
        result[tuple(peak_idx.T)] = True
388
        assert np.all(result == expected)
389

390
    def test_disk(self):
391
        '''regression test of img-1194, footprint = [1]
392
        Test peak.peak_local_max when every point is a local maximum
393
        '''
394
        image = np.random.uniform(size=(10, 20))
395
        footprint = np.array([[1]])
396
        peak_idx = peak.peak_local_max(
397
            image,
398
            labels=np.ones((10, 20), int),
399
            footprint=footprint,
400
            min_distance=1,
401
            threshold_rel=0,
402
            threshold_abs=-1,
403
            exclude_border=False,
404
        )
405
        result = np.zeros_like(image, dtype=bool)
406
        result[tuple(peak_idx.T)] = True
407
        assert np.all(result)
408
        peak_idx = peak.peak_local_max(
409
            image, footprint=footprint, threshold_abs=-1, exclude_border=False
410
        )
411
        result = np.zeros_like(image, dtype=bool)
412
        result[tuple(peak_idx.T)] = True
413
        assert np.all(result)
414

415
    def test_3D(self):
416
        image = np.zeros((30, 30, 30))
417
        image[15, 15, 15] = 1
418
        image[5, 5, 5] = 1
419
        assert_array_equal(
420
            peak.peak_local_max(image, min_distance=10, threshold_rel=0), [[15, 15, 15]]
421
        )
422
        assert_array_equal(
423
            peak.peak_local_max(image, min_distance=6, threshold_rel=0), [[15, 15, 15]]
424
        )
425
        assert sorted(
426
            peak.peak_local_max(
427
                image, min_distance=10, threshold_rel=0, exclude_border=False
428
            ).tolist()
429
        ) == [[5, 5, 5], [15, 15, 15]]
430
        assert sorted(
431
            peak.peak_local_max(image, min_distance=5, threshold_rel=0).tolist()
432
        ) == [[5, 5, 5], [15, 15, 15]]
433

434
    def test_4D(self):
435
        image = np.zeros((30, 30, 30, 30))
436
        image[15, 15, 15, 15] = 1
437
        image[5, 5, 5, 5] = 1
438
        assert_array_equal(
439
            peak.peak_local_max(image, min_distance=10, threshold_rel=0),
440
            [[15, 15, 15, 15]],
441
        )
442
        assert_array_equal(
443
            peak.peak_local_max(image, min_distance=6, threshold_rel=0),
444
            [[15, 15, 15, 15]],
445
        )
446
        assert sorted(
447
            peak.peak_local_max(
448
                image, min_distance=10, threshold_rel=0, exclude_border=False
449
            ).tolist()
450
        ) == [[5, 5, 5, 5], [15, 15, 15, 15]]
451
        assert sorted(
452
            peak.peak_local_max(image, min_distance=5, threshold_rel=0).tolist()
453
        ) == [[5, 5, 5, 5], [15, 15, 15, 15]]
454

455
    def test_threshold_rel_default(self):
456
        image = np.ones((5, 5))
457

458
        image[2, 2] = 1
459
        assert len(peak.peak_local_max(image)) == 0
460

461
        image[2, 2] = 2
462
        assert_array_equal(peak.peak_local_max(image), [[2, 2]])
463

464
        image[2, 2] = 0
465
        with expected_warnings(["When min_distance < 1"]):
466
            assert len(peak.peak_local_max(image, min_distance=0)) == image.size - 1
467

468
    def test_peak_at_border(self):
469
        image = np.full((10, 10), -2)
470
        image[2, 4] = -1
471
        image[3, 0] = -1
472

473
        peaks = peak.peak_local_max(image, min_distance=3)
474
        assert peaks.size == 0
475

476
        peaks = peak.peak_local_max(image, min_distance=3, exclude_border=0)
477
        assert len(peaks) == 2
478
        assert [2, 4] in peaks
479
        assert [3, 0] in peaks
480

481

482
@pytest.mark.parametrize(
483
    ["indices"],
484
    [[indices] for indices in itertools.product(range(5), range(5))],
485
)
486
def test_exclude_border(indices):
487
    image = np.zeros((5, 5))
488
    image[indices] = 1
489

490
    # exclude_border = False, means it will always be found.
491
    assert len(peak.peak_local_max(image, exclude_border=False)) == 1
492

493
    # exclude_border = 0, means it will always be found.
494
    assert len(peak.peak_local_max(image, exclude_border=0)) == 1
495

496
    # exclude_border = True, min_distance=1 means it will be found unless it's
497
    # on the edge.
498
    if indices[0] in (0, 4) or indices[1] in (0, 4):
499
        expected_peaks = 0
500
    else:
501
        expected_peaks = 1
502
    assert (
503
        len(peak.peak_local_max(image, min_distance=1, exclude_border=True))
504
        == expected_peaks
505
    )
506

507
    # exclude_border = (1, 0) means it will be found unless it's on the edge of
508
    # the first dimension.
509
    if indices[0] in (0, 4):
510
        expected_peaks = 0
511
    else:
512
        expected_peaks = 1
513
    assert len(peak.peak_local_max(image, exclude_border=(1, 0))) == expected_peaks
514

515
    # exclude_border = (0, 1) means it will be found unless it's on the edge of
516
    # the second dimension.
517
    if indices[1] in (0, 4):
518
        expected_peaks = 0
519
    else:
520
        expected_peaks = 1
521
    assert len(peak.peak_local_max(image, exclude_border=(0, 1))) == expected_peaks
522

523

524
def test_exclude_border_errors():
525
    image = np.zeros((5, 5))
526

527
    # exclude_border doesn't have the right cardinality.
528
    with pytest.raises(ValueError):
529
        assert peak.peak_local_max(image, exclude_border=(1,))
530

531
    # exclude_border doesn't have the right type
532
    with pytest.raises(TypeError):
533
        assert peak.peak_local_max(image, exclude_border=1.0)
534

535
    # exclude_border is a tuple of the right cardinality but contains
536
    # non-integer values.
537
    with pytest.raises(ValueError):
538
        assert peak.peak_local_max(image, exclude_border=(1, 'a'))
539

540
    # exclude_border is a tuple of the right cardinality but contains a
541
    # negative value.
542
    with pytest.raises(ValueError):
543
        assert peak.peak_local_max(image, exclude_border=(1, -1))
544

545
    # exclude_border is a negative value.
546
    with pytest.raises(ValueError):
547
        assert peak.peak_local_max(image, exclude_border=-1)
548

549

550
def test_input_values_with_labels():
551
    # Issue #5235: input values may be modified when labels are used
552

553
    img = np.random.rand(128, 128)
554
    labels = np.zeros((128, 128), int)
555

556
    labels[10:20, 10:20] = 1
557
    labels[12:16, 12:16] = 0
558

559
    img_before = img.copy()
560

561
    _ = peak.peak_local_max(img, labels=labels)
562

563
    assert_array_equal(img, img_before)
564

565

566
class TestProminentPeaks:
567
    def test_isolated_peaks(self):
568
        image = np.zeros((15, 15))
569
        x0, y0, i0 = (12, 8, 1)
570
        x1, y1, i1 = (2, 2, 1)
571
        x2, y2, i2 = (5, 13, 1)
572
        image[y0, x0] = i0
573
        image[y1, x1] = i1
574
        image[y2, x2] = i2
575
        out = peak._prominent_peaks(image)
576
        assert len(out[0]) == 3
577
        for i, x, y in zip(out[0], out[1], out[2]):
578
            assert i in (i0, i1, i2)
579
            assert x in (x0, x1, x2)
580
            assert y in (y0, y1, y2)
581

582
    def test_threshold(self):
583
        image = np.zeros((15, 15))
584
        x0, y0, i0 = (12, 8, 10)
585
        x1, y1, i1 = (2, 2, 8)
586
        x2, y2, i2 = (5, 13, 10)
587
        image[y0, x0] = i0
588
        image[y1, x1] = i1
589
        image[y2, x2] = i2
590
        out = peak._prominent_peaks(image, threshold=None)
591
        assert len(out[0]) == 3
592
        for i, x, y in zip(out[0], out[1], out[2]):
593
            assert i in (i0, i1, i2)
594
            assert x in (x0, x1, x2)
595
        out = peak._prominent_peaks(image, threshold=9)
596
        assert len(out[0]) == 2
597
        for i, x, y in zip(out[0], out[1], out[2]):
598
            assert i in (i0, i2)
599
            assert x in (x0, x2)
600
            assert y in (y0, y2)
601

602
    def test_peaks_in_contact(self):
603
        image = np.zeros((15, 15))
604
        x0, y0, i0 = (8, 8, 1)
605
        x1, y1, i1 = (7, 7, 1)  # prominent peak
606
        x2, y2, i2 = (6, 6, 1)
607
        image[y0, x0] = i0
608
        image[y1, x1] = i1
609
        image[y2, x2] = i2
610
        out = peak._prominent_peaks(
611
            image,
612
            min_xdistance=3,
613
            min_ydistance=3,
614
        )
615
        assert_equal(out[0], np.array((i1,)))
616
        assert_equal(out[1], np.array((x1,)))
617
        assert_equal(out[2], np.array((y1,)))
618

619
    def test_input_labels_unmodified(self):
620
        image = np.zeros((10, 20))
621
        labels = np.zeros((10, 20), int)
622
        image[5, 5] = 1
623
        labels[5, 5] = 3
624
        labelsin = labels.copy()
625
        peak.peak_local_max(
626
            image,
627
            labels=labels,
628
            footprint=np.ones((3, 3), bool),
629
            min_distance=1,
630
            threshold_rel=0,
631
            exclude_border=False,
632
        )
633
        assert np.all(labels == labelsin)
634

635
    def test_many_objects(self):
636
        mask = np.zeros([500, 500], dtype=bool)
637
        x, y = np.indices((500, 500))
638
        x_c = x // 20 * 20 + 10
639
        y_c = y // 20 * 20 + 10
640
        mask[(x - x_c) ** 2 + (y - y_c) ** 2 < 8**2] = True
641
        labels, num_objs = ndi.label(mask)
642
        dist = ndi.distance_transform_edt(mask)
643
        local_max = peak.peak_local_max(
644
            dist, min_distance=20, exclude_border=False, labels=labels
645
        )
646
        assert len(local_max) == 625
647

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

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

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

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