janelia-flyem / dvid

Distributed, Versioned, Image-oriented Dataservice
http://dvid.io
Other
196 stars 33 forks source link

API for all supervoxel sizes within a body #262

Closed stuarteberg closed 2 years ago

stuarteberg commented 6 years ago

It would be nice if I could query for all of a body's supervoxels and their sizes simultaneously. The API could be something like this:

GET http://{server}/api/node/{uuid}/{labelmap_instance}/supervoxel-sizes/{body_id}

...which would return something like this:

{
    "supervoxels": [1,2,3,4,...],
    "sizes": [100,200,300,400,...]
}

Right now, fetching the size of all supervoxels in the body requires two API calls:

In [343]: svs = requests.get('http://emdata3:8900/api/node/8e72/segmentation/supervoxels/5813024978').json()

In [344]: sizes = requests.get('http://emdata3:8900/api/node/8e72/segmentation/sizes?supervoxels=true', json=svs).json()

The first call is quite fast (63 ms), but the second is very slow (1 minute). I assume that's because the LabelIndex data structure is completely traversed for every supervoxel in the list. But if you know that the supervoxels all belong to the same body, the LabelIndex can be traversed only once.

DocSavage commented 6 years ago

Per conversation with Stuart, I will provide GET /index/{body_id} endpoint as fetch version of the POST on that same endpoint. It will return a protobuf serialization of the label index that includes supervoxels in the body as well as the voxel distribution across blocks. This should be a very fast GET since it will return a label index with minimal processing.

stuarteberg commented 2 years ago

For particularly large bodies, this feature would indeed be useful. In particular, it would simplify things for NeuTu/neu3, and would fix the problem seen in https://github.com/janelia-flyem/NeuTu/issues/375.

In fact, as a related point: If someone runs GET .../sizes?supervoxels=true, it would be great if DVID could check to see which bodies those supervoxels belong to, and only read each relevant labelindex one time, rather than reading each labelindex N times repeatedly for N supervoxels which happen to share the same body.