cloud-volume
cloud-volume copied to clipboard
extract the bounding box of a segment
I know the mesh and the skeleton can be downloaded using the label ID, but how to obtain all the volume (EM & segment region) belonging to a certain segment. The bounding box around a segment ID should work, but how to obtain the information of that bounding box? Is there a way to obtain this bounding box using cloud-volume or from neuroglancer?
Hi! This is possible if your dataset was created with a spatial index. Currently, no spatial index exists for images, but by default, igneous generates them for meshes and skeletons.
If the index exists, you can access the index as:
cv.mesh.spatial_index.get_bbox(label)
cv.skeleton.spatial_index.get_bbox(label)
get_bbox is a less used feature, so it could be buggy. Let me know if you have problems with it.
The spatial index consists of a set of JSON files that spans the whole dataset. get_bbox
downloads and parses all the json files to extract the bbox. If you are running many of these queries it might make sense to convert them into a sqlite database using cv.mesh.spatial_index.to_sqlite(...)
whose filepath you can then pass in to CloudVolume to enable faster lookups.
If your dataset does not have a spatial index, you can create one with igneous using the command igneous mesh spatial-index create PATH_TO_DATASET --queue queue --mip MIP
and igneous execute queue
. You can also download the mesh spatial db into a sqlite database using the command igneous mesh spatial-index db PATH_TO_DATASET spatial_index.db
. Unfortunately, I haven't yet added spatial index commands to igneous's CLI for skeletons for adding it ex post facto, but they will be automatically created during the forging process.
That's a lot of info. The spatial index has been primarily used by myself so there might be some rough edges for other people. Let me know how you like it!
Spatial index code: https://github.com/seung-lab/cloud-volume/blob/master/cloudvolume/datasource/precomputed/spatial_index.py
Thanks! I was actually trying to download the data from one public dataset, and sadly they don't have that spatial_index information.
I think then that the only way to do it (other than exploiting skeleton and mesh information) is to download the volume in chunks and extract the bounding box information that way (i.e. generate your own spatial_index). I recently improved the means to test whether an ID is in a given region using cv.unique
and accelerated point lookups, but I don't think that is what you want.
I recently discovered that Neuroglancer has its own version of the spatial index that is not currently supported by CloudVolume. You might have some fruitful exploration with this specification: https://github.com/google/neuroglancer/blob/master/src/neuroglancer/datasource/precomputed/annotations.md
Thank you so much! This link cleared many confusions of mine.