-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmax_projection.py
More file actions
64 lines (51 loc) · 1.73 KB
/
max_projection.py
File metadata and controls
64 lines (51 loc) · 1.73 KB
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
import argparse
import webbrowser
import neuroglancer
import numpy as np
import neuroglancer.cli
def create_volume():
shape = (10, 40, 50)
# Create the volume
volume = np.zeros(shape)
# Fill each row across the last dimension with 90 random data points and 10 data points that are 1s
rng = np.random.default_rng()
for i in range(shape[0]):
for j in range(shape[1]):
random_indices = rng.choice(shape[2], size=40, replace=False)
volume[i, j, random_indices] = rng.random(40)
volume[i, j, ~np.isin(np.arange(shape[2]), random_indices)] = 1
return volume
def add_image_layer(state):
dimensions = neuroglancer.CoordinateSpace(
names=["x", "y", "z"], units="nm", scales=[40, 40, 40]
)
local_volume = neuroglancer.LocalVolume(create_volume(), dimensions)
state.layers["image"] = neuroglancer.ImageLayer(
source=local_volume, volume_rendering_mode="max", shader=get_shader()
)
state.layout = "3d"
state.show_axis_lines = False
def get_shader():
return """
#uicontrol invlerp normalized(range=[0,1])
void main() {
emitGrayscale(normalized());
}
"""
def launch_nglancer():
ap = argparse.ArgumentParser()
neuroglancer.cli.add_server_arguments(ap)
args = ap.parse_args()
neuroglancer.cli.handle_server_arguments(args)
viewer = neuroglancer.Viewer()
return viewer
if __name__ == "__main__":
viewer = launch_nglancer()
with viewer.txn() as s:
add_image_layer(s)
webbrowser.open_new(viewer.get_viewer_url())
s1 = viewer.screenshot(size=[100, 100])
print("shot 1 taken")
with open("p1.png", "wb") as f:
print(s1.screenshot.resolution_metadata)
f.write(s1.screenshot.image)