-
Notifications
You must be signed in to change notification settings - Fork 44
/
test_generate_n_most_touching_neighbors_matrix.py
44 lines (36 loc) · 1.37 KB
/
test_generate_n_most_touching_neighbors_matrix.py
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
37
38
39
40
41
42
43
44
def test_generate_n_most_touching_neighbors_matrix():
import numpy as np
import pyclesperanto_prototype as cle
labels = cle.asarray([
[0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 0, 2, 2, 0],
[0, 1, 1, 1, 2, 2, 0],
[0, 0, 3, 3, 3, 3, 0],
[0, 0, 4, 4, 4, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
])
labels = cle.scale(labels, factor_x=10, factor_y=10, auto_size=True).astype(np.uint32)
reference = cle.asarray([
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 1., 1., 0., 0.],
[0., 0., 0., 1., 0.],
])
touch_count_matrix = cle.generate_touch_count_matrix(labels)
print(touch_count_matrix)
result = cle.generate_n_most_touching_neighbors_matrix(touch_count_matrix, n=1)
assert cle.array_equal(reference, result)
touch_portion_matrix = cle.generate_touch_portion_matrix(labels)
print(touch_portion_matrix)
result = cle.generate_n_most_touching_neighbors_matrix(touch_portion_matrix, n=1)
assert cle.array_equal(reference, result)
reference = cle.asarray([
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 1., 0., 0., 0.],
[0., 1., 1., 0., 0.],
[0., 0., 0., 1., 0.],
])
result = cle.generate_n_most_touching_neighbors_matrix(touch_portion_matrix, n=2)
assert cle.array_equal(reference, result)