|
4 | 4 | import neuroglancer.cli |
5 | 5 | import nrrd |
6 | 6 | from pathlib import Path |
| 7 | +from cloudvolume import CloudVolume |
7 | 8 |
|
8 | 9 | HERE = Path(__file__).parent |
9 | | -NRRD_FILE_PATH = HERE / "volume1.nrrd" |
10 | 10 |
|
| 11 | +NAMES = ["12vj", "1567", "101b"] |
| 12 | +PATHS = [HERE / f"{name}.nrrd" for name in NAMES] |
| 13 | +OUTPUT_PATHS = [f"file://datasets/{name}" for name in NAMES] |
11 | 14 |
|
12 | | -def add_image_layer(state): |
13 | | - readdata, header = nrrd.read(NRRD_FILE_PATH) |
| 15 | + |
| 16 | +def convert_to_precomputed(nrrd_path, output_path): |
| 17 | + readdata, header = nrrd.read(nrrd_path) |
| 18 | + # Cloud volume expects resolution in nm - but given in um |
| 19 | + scales = [header["space directions"][i][i] * 1000 for i in range(3)] |
| 20 | + CloudVolume.from_numpy( |
| 21 | + readdata, |
| 22 | + vol_path=output_path, |
| 23 | + chunk_size=(256, 256, 128), |
| 24 | + resolution=scales, |
| 25 | + layer_type="image", |
| 26 | + progress=True, |
| 27 | + compress=False, |
| 28 | + ) |
| 29 | + |
| 30 | + |
| 31 | +def add_image_layer(state, path, name="image"): |
| 32 | + readdata, header = nrrd.read(path) |
14 | 33 | scales = [header["space directions"][i][i] for i in range(3)] |
15 | 34 | dimensions = neuroglancer.CoordinateSpace( |
16 | 35 | names=["x", "y", "z"], units="um", scales=scales |
17 | 36 | ) |
18 | 37 | data = readdata |
19 | 38 | local_volume = neuroglancer.LocalVolume(data, dimensions) |
20 | 39 | state.layers.append( |
21 | | - name="image", |
| 40 | + name=name, |
22 | 41 | layer=neuroglancer.ImageLayer( |
23 | 42 | source=local_volume, |
24 | 43 | volume_rendering_mode="ON", |
@@ -47,7 +66,12 @@ def launch_nglancer(): |
47 | 66 | def main(): |
48 | 67 | viewer = launch_nglancer() |
49 | 68 | with viewer.txn() as s: |
50 | | - add_image_layer(s) |
| 69 | + for i in range(3): |
| 70 | + convert_to_precomputed(PATHS[i], OUTPUT_PATHS[i]) |
| 71 | + path = PATHS[i] |
| 72 | + name = NAMES[i] |
| 73 | + add_image_layer(s, path, name) |
| 74 | + exit(-1) |
51 | 75 | webbrowser.open_new(viewer.get_viewer_url()) |
52 | 76 |
|
53 | 77 |
|
|
0 commit comments