forked from google/neuroglancer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_skeletons.py
63 lines (51 loc) · 1.96 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
from __future__ import print_function
import argparse
import numpy as np
import neuroglancer
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):
super(SkeletonSource, self).__init__()
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')[::-1]
vertex_positions = [pos * voxel_size, pos * voxel_size + np.random.randn(3) * 300]
edges = [0, 1]
return neuroglancer.skeleton.Skeleton(
vertex_positions=vertex_positions,
edges=edges,
vertex_attributes=dict(affinity=np.random.rand(2), affinity2=np.random.rand(2)))
viewer = neuroglancer.Viewer()
with viewer.txn() as s:
s.layers.append(
name='a',
layer=neuroglancer.SegmentationLayer(
source=neuroglancer.LocalVolume(
data=segmentation,
voxel_size=voxel_size,
skeletons=SkeletonSource(),
),
skeleton_shader='void main() { emitRGB(colormapJet(affinity)); }',
selected_alpha=0,
not_selected_alpha=0,
))
if __name__ == '__main__':
ap = argparse.ArgumentParser()
ap.add_argument('--static-content-url')
ap.add_argument('-a', '--bind-address')
args = ap.parse_args()
neuroglancer.server.debug = True
if args.bind_address:
neuroglancer.set_server_bind_address(args.bind_address)
if args.static_content_url:
neuroglancer.set_static_content_source(url=args.static_content_url)
print(viewer)