-
Notifications
You must be signed in to change notification settings - Fork 19
/
branchoid.py
92 lines (70 loc) · 2.84 KB
/
branchoid.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def branchoid(size:int = 100, sigma:float = 1, threshold:float = 0.5):
"""
Creates a synthetical binary image dataset of a sphere that has other sphere-, cone- and cylinder-like structures growing out of it.
Parameters
----------
size:int, optional
Width/height/depth of the resulting binary image dataset
sigma:float, optional
after creating the dataset, it will be blurred to potentially smooth the surface
threshold: float, optional
by increasing the threshold, the object volume will become larger
Returns
-------
ndarray
"""
import pyclesperanto_prototype as cle
import stackview
image = cle.create([size, size, size])
cle.set(image, 0)
cle.draw_sphere(image, size*0.5, size*0.5, size*0.5, radius_x=size*0.25, radius_y=size*0.25, radius_z=size*0.25)
for i in range(0, 10):
radius = size * (0.25 - i*0.01)
cle.draw_sphere(image,
size*0.5 + i * size * 0.02,
size*0.5,
size*0.5,
radius_x=radius,
radius_y=radius,
radius_z=radius)
for i in range(0, 10):
radius = size * (0.15 - i*0.01)
cle.draw_sphere(image,
size*0.5,
size*0.65 + i * size * 0.02,
size*0.5,
radius_x=radius,
radius_y=radius,
radius_z=radius)
for i in range(0, 10):
radius = size * (0.12 - i*0.01)
cle.draw_sphere(image,
size*0.35 - i * size * 0.02,
size*0.65 + i * size * 0.02,
size*0.5,
radius_x=radius,
radius_y=radius,
radius_z=radius)
for i in range(0, 10):
radius = size * (0.05)
cle.draw_sphere(image,
size*0.35 - i * size * 0.02,
size*0.5,
size*0.5,
radius_x=radius,
radius_y=radius,
radius_z=radius)
for i in range(0, 20):
if i < 10:
radius = size * (0.05)
else:
radius = size * (0.05 + (i-10)*0.01)
cle.draw_sphere(image,
size*0.35 - i * size * 0.01,
size*0.35 - i * size * 0.01,
size*0.5,
radius_x=radius,
radius_y=radius,
radius_z=radius)
smoothed_branchoid = cle.gaussian_blur(image, sigma_x = sigma, sigma_y = sigma, sigma_z = sigma)
return stackview.insight(cle.pull(smoothed_branchoid > 0.5))