-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathng_utils.py
More file actions
58 lines (46 loc) · 1.62 KB
/
Copy pathng_utils.py
File metadata and controls
58 lines (46 loc) · 1.62 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Atchuth Naveen
Contains Utilities to open a neuroglancer instance and feed data.
"""
import neuroglancer
import numpy as np
import imageio
import webbrowser
from time import sleep
res = neuroglancer.CoordinateSpace(
names=['z', 'y', 'x'],
units=['um', 'um', 'um'],
scales=[50, 1.25, 1.25])
def ng_createViewer():
"""
Create a local neuroglancer Viewer
"""
neuroglancer.set_static_content_source()
viewer=neuroglancer.Viewer()
return viewer
def ng_SingleSectionLocalViewer(image, annotations=None, viewer=None):
"""
image : 2D np array representing the image - gets expanded to 3D
annotations: nx2 np array of cell locations
"""
def ngLayer(data,res,oo=[0,0,0],tt='segmentation'):
return neuroglancer.LocalVolume(data,dimensions=res,volume_type=tt,voxel_offset=oo)
if viewer is None:
viewer = ng_createViewer()
counter =0
with viewer.txn() as s:
s.layers.append(name='im',layer=ngLayer(np.expand_dims(image,axis=0),res,tt='image'))
with viewer.txn() as s:
s.crossSectionScale = 1
if annotations is not None:
with viewer.txn() as s:
s.layers['annotation'] = neuroglancer.AnnotationLayer()
ann = s.layers['annotation'].annotations
# each point annotation has a unique id
for x,y in annotations:
pt = neuroglancer.PointAnnotation(point=[1,x, y], id=f'point{counter}')
ann.append(pt)
counter += 1
return viewer