This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
forked from mit-ll/NeuroTrALE-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_annotations.py
70 lines (60 loc) · 2.23 KB
/
write_annotations.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
import argparse
import atexit
import shutil
import tempfile
import neuroglancer
import neuroglancer.cli
import neuroglancer.static_file_server
import neuroglancer.write_annotations
import numpy as np
def write_some_annotations(
output_dir: str, coordinate_space: neuroglancer.CoordinateSpace
):
writer = neuroglancer.write_annotations.AnnotationWriter(
coordinate_space=coordinate_space,
annotation_type="point",
properties=[
neuroglancer.AnnotationPropertySpec(id="size", type="float32"),
neuroglancer.AnnotationPropertySpec(id="cell_type", type="uint16"),
neuroglancer.AnnotationPropertySpec(id="point_color", type="rgba"),
],
)
writer.add_point([20, 30, 40], size=10, cell_type=16, point_color=(0, 255, 0, 255))
writer.add_point([50, 51, 52], size=30, cell_type=16, point_color=(255, 0, 0, 255))
writer.write(output_dir)
if __name__ == "__main__":
ap = argparse.ArgumentParser()
neuroglancer.cli.add_server_arguments(ap)
args = ap.parse_args()
neuroglancer.cli.handle_server_arguments(args)
viewer = neuroglancer.Viewer()
tempdir = tempfile.mkdtemp()
atexit.register(shutil.rmtree, tempdir)
coordinate_space = neuroglancer.CoordinateSpace(
names=["x", "y", "z"], units=["nm", "nm", "nm"], scales=[10, 10, 10]
)
write_some_annotations(output_dir=tempdir, coordinate_space=coordinate_space)
server = neuroglancer.static_file_server.StaticFileServer(
static_dir=tempdir, bind_address=args.bind_address or "127.0.0.1", daemon=True
)
with viewer.txn() as s:
s.layers["image"] = neuroglancer.ImageLayer(
source=neuroglancer.LocalVolume(
data=np.full(fill_value=200, shape=(100, 100, 100), dtype=np.uint8),
dimensions=coordinate_space,
),
)
s.layers["annotations"] = neuroglancer.AnnotationLayer(
source=f"precomputed://{server.url}",
tab="rendering",
shader="""
void main() {
setColor(prop_point_color());
setPointMarkerSize(prop_size());
}
""",
)
s.selected_layer.layer = "annotations"
s.selected_layer.visible = True
s.show_slices = False
print(viewer)