-
Notifications
You must be signed in to change notification settings - Fork 302
/
Copy pathexample_skeletons.py
76 lines (65 loc) · 2.3 KB
/
example_skeletons.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
import argparse
import neuroglancer
import neuroglancer.cli
import numpy as np
voxel_size = np.array([10, 10, 10])
shape = (100, 100, 100)
segmentation = np.arange(np.prod(shape), dtype=np.uint32).reshape(shape)
class SkeletonSource(neuroglancer.skeleton.SkeletonSource):
def __init__(self, dimensions):
super().__init__(dimensions)
self.vertex_attributes["affinity"] = neuroglancer.skeleton.VertexAttributeInfo(
data_type=np.float32,
num_components=1,
)
self.vertex_attributes["affinity2"] = neuroglancer.skeleton.VertexAttributeInfo(
data_type=np.float32,
num_components=1,
)
def get_skeleton(self, i):
pos = np.unravel_index(i, shape, order="C")
gen = np.random.default_rng()
vertex_positions = [pos, pos + gen.randn(3) * 30]
edges = [[0, 1]]
return neuroglancer.skeleton.Skeleton(
vertex_positions=vertex_positions,
edges=edges,
vertex_attributes=dict(affinity=gen.rand(2), affinity2=gen.rand(2)),
)
viewer = neuroglancer.Viewer()
dimensions = neuroglancer.CoordinateSpace(
names=["x", "y", "z"],
units="nm",
scales=[10, 10, 10],
)
with viewer.txn() as s:
s.layers.append(
name="a",
layer=neuroglancer.SegmentationLayer(
source=[
neuroglancer.LocalVolume(
data=segmentation,
dimensions=dimensions,
),
SkeletonSource(dimensions),
],
skeleton_shader="void main() { emitRGB(colormapJet(affinity)); }",
selected_alpha=0,
not_selected_alpha=0,
segments=[395750],
),
)
# Can adjust the skeleton rendering options
s.layers[0].skeleton_rendering.mode2d = "lines"
s.layers[0].skeleton_rendering.line_width2d = 3
s.layers[0].skeleton_rendering.mode3d = "lines_and_points"
s.layers[0].skeleton_rendering.line_width3d = 10
# Can adjust visibility of layer side panel
s.selected_layer.layer = "a"
s.selected_layer.visible = True
if __name__ == "__main__":
ap = argparse.ArgumentParser()
neuroglancer.cli.add_server_arguments(ap)
args = ap.parse_args()
neuroglancer.cli.handle_server_arguments(args)
print(viewer)