Last active
July 6, 2022 13:14
-
-
Save pieper/0e7edcf70c844925ea104e07aedbe92a to your computer and use it in GitHub Desktop.
Display NGFF volume data in 3D Slicer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Display zarr from s3 buckets for example data from here: | |
https://www.openmicroscopy.org/2020/11/04/zarr-data.html | |
exec(open("/Users/pieper/idc/ngff.py").read()) | |
see also: /Volumes/GoogleDrive/My\ Drive/hacks/sardana.py | |
https://gist.github.com/pieper/10ee6add544633f4c75dbb293ef087bc | |
""" | |
import numpy | |
try: | |
import ome_zarr | |
except: | |
pip_install("ome-zarr") | |
import ome_zarr | |
import ome_zarr.io | |
import ome_zarr.reader | |
# idr0044 from https://www.openmicroscopy.org/2020/11/04/zarr-data.html | |
zarrEndpoint = "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.1/4007801.zarr" | |
location = ome_zarr.io.parse_url(zarrEndpoint) | |
reader = ome_zarr.reader.Reader(location) | |
nodes = [node for node in reader()] | |
node = nodes[0] | |
level = len(node.data) - 3 | |
timePoint = int(node.data[level].shape[0] / 2) | |
channel = 1 | |
volume = node.data[level][timePoint][channel] | |
voxelType=vtk.VTK_UNSIGNED_SHORT | |
dimensions = list(volume.shape) | |
dimensions.reverse() | |
imageData = vtk.vtkImageData() | |
imageData.SetDimensions(dimensions) | |
imageData.AllocateScalars(voxelType, 1) | |
volumeNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeNode", "Zarr Volume") | |
volumeNode.SetAndObserveImageData(imageData) | |
volumeNode.CreateDefaultDisplayNodes() | |
volumeNode.CreateDefaultStorageNode() | |
array = slicer.util.arrayFromVolume(volumeNode) | |
array[:] = volume | |
slicer.util.arrayFromVolumeModified(volumeNode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment