Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract the bounding box of a segment #519

Open
BoyuLyu opened this issue Jan 22, 2022 · 5 comments
Open

extract the bounding box of a segment #519

BoyuLyu opened this issue Jan 22, 2022 · 5 comments
Labels
question What is going on??? :thinking emoji:

Comments

@BoyuLyu
Copy link

BoyuLyu commented Jan 22, 2022

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?

@william-silversmith william-silversmith added the question What is going on??? :thinking emoji: label Jan 22, 2022
@william-silversmith
Copy link
Contributor

william-silversmith commented Jan 22, 2022

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

@BoyuLyu
Copy link
Author

BoyuLyu commented Jan 25, 2022

Thanks! I was actually trying to download the data from one public dataset, and sadly they don't have that spatial_index information.

@william-silversmith
Copy link
Contributor

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.

@william-silversmith
Copy link
Contributor

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

@BoyuLyu
Copy link
Author

BoyuLyu commented Feb 3, 2022

Thank you so much! This link cleared many confusions of mine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question What is going on??? :thinking emoji:
Projects
None yet
Development

No branches or pull requests

2 participants