-
Notifications
You must be signed in to change notification settings - Fork 43
/
perf.py
68 lines (59 loc) · 1.75 KB
/
perf.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import cc3d
from tqdm import tqdm
import scipy.ndimage.measurements
import numpy as np
import time
import fastremap
def cc3d_test_multilabel(labels):
labels, remap = fastremap.renumber(labels)
res = cc3d.connected_components(labels)
N = np.max(labels)
for segid in tqdm(range(1, N+1)):
extracted = (res == segid)
def cc3d_test_multilabel_series(labels):
res = cc3d.connected_components(labels)
for label, img in tqdm(cc3d.series(res, in_place=True)):
pass
def ndimage_test_multilabel(labels):
s = [
[[1,1,1], [1,1,1], [1,1,1]],
[[1,1,1], [1,1,1], [1,1,1]],
[[1,1,1], [1,1,1], [1,1,1]]
]
uniques = np.unique(labels)[1:]
for segid in tqdm(uniques):
extracted = (labels == segid)
res, N = scipy.ndimage.measurements.label(extracted, structure=s)
for ccid in tqdm(range(1,N+1)):
extracted = (res == ccid)
def ndimage_binary_image(labels, connectivity=26):
if connectivity == 26:
s = [
[[1,1,1], [1,1,1], [1,1,1]],
[[1,1,1], [1,1,1], [1,1,1]],
[[1,1,1], [1,1,1], [1,1,1]]
]
elif connectivity == 6:
s = None
else:
raise ValueError("Unsupported connectivity. " + str(connectivity))
for label in labels:
scipy.ndimage.measurements.label(label, structure=s) # black
def cc3d_binary_image(labels, connectivity=26):
for label in labels:
cc3d.connected_components(label, connectivity=connectivity) # blue
# binary tests
s = time.time()
labels = [
np.random.randint(0,2, size=(384, 384, 384), dtype=np.bool)
for _ in range(10)
]
print(time.time() - s)
s = time.time()
cc3d_binary_image(labels, 6)
# ndimage_binary_image(labels, 6)
print(time.time() - s)
# multilabel tests
# labels = np.random.randint(0,100, (512,512,512), dtype=np.uint8)
# ndimage_test(labels)
# cc3d_test(labels)