Skip to content

Getting Cutouts with CloudVolume

William Silversmith edited this page Sep 6, 2017 · 1 revision

If you are interested in getting arbitrary 3D multichannel image cutouts from Neuroglancer's Google Storage, Amazon S3, The BOSS, and local FS follow this guide to get started.

Note that everything is XYZ order except the python server!

Installation

pip install cloud-volume

Reading Images with CloudVolume

from cloudvolume import CloudVolume

# Pseudocode:
# vol = CloudVolume(cloudpath, mip)

# Real Example: Get all of S1 segmentation downsampled once
vol = CloudVolume('gs://neuroglancer/s1_v0/segmentation', mip=1)

# indexes are in terms of mip level, so 1 pixel at mip 1 is 2 pixels at mip 0 for isotropic datasets
segmentation = vol[x1:x2,y1:y2,z1:z2]

The object returned from vol[:,:,:] is an instance of VolumeCutout, a subclass of np.ndarray. You can do anything you would ordinarily be inclined to do with a numpy array. However, if you'd like to visualize the data associated with this cutout, it comes with a method save_images which will write axis aligned (default z-axis) sliced PNGs to disk in './staging/' .

Writing Images with CloudVolume

Let's say you are manipulating a dataset and you want to save a sector of processed image to gcloud. You have a 3D or 4D numpy array and know its voxel offset into the volume at the given mip level:

 from cloudvolume import CloudVolume

 # img is a 3D or 4D (for multichannel) numpy array
 # offset is an x,y,z tuple like (10,2,7)
 img, offset = get_processed_image()

 vol = CloudVolume('s3://neuroglancer/segmentation', mip=0)

 vol[ 10:20, 2:10, 7:10, : ] = img

Updating Info Files

You can also use CloudVolume to edit the info metadata files that drive neuroglancer and the ingestion process.

 from cloudvolume import CloudVolume

 vol = CloudVolume('gs://neuroglancer/test_v0/segmentation/', mip=0)

 vol.info['$MYATTR'] = $MYVALUE

 vol.commitInfo() # uploads changes to the cloud

Other Features

You can get lots of helpful information about the volume from:

vol.info # all about this volume
vol.layer_type # e.g. 'segmentation', 'image'
vol.data_type # e.g. 'uint32'

# for this mip level
vol.underlying # e.g. (64,64,64)
vol.shape # size of dataset e.g. (2048, 2048, 256)
vol.downsample_ratio