google / neuroglancer

WebGL-based viewer for volumetric data
Apache License 2.0
1.08k stars 295 forks source link

Add segment IDs by their text labels programmatically? (with neuroglancer_segment_properties) #398

Open j6k4m8 opened 2 years ago

j6k4m8 commented 2 years ago

Hey @jbms — I read through the docs and some comments in #199 and I don't think there's an easy way to do this currently:

If I have a segmentation channel with IDs [1, 2, 3, 4] and a neuroglancer_segment_properties info that looks like this:

{
    "inline": {
        "ids": ["1", "2", "3", "4"],
        "properties": [{
            "type": "label",
            "id": "label",
            "values": ["John", "Paul", "George", "Ringo"]
        }]
    }
}

Is there an easy way to add Ringo to the segments array of my ngl state object at pageload, if I don't know what ID that corresponds to?

Right now, I need to know that Ringo corresponds to segment "4" so that I can populate state like this:

... // in `layers[]`
{
    "type": "segmentation",
    "source": [
      "precomputed://.../segmentation",
      "precomputed://.../properties"
    ],
    "tab": "source",
    "segments": [
      "4",                             // Works
      "Ringo"                          // Doesn't Work
    ],
    "name": "segmentation"
},
...

Is there a way for me to specify the label instead of the segment ID, and let neuroglancer run the lookup at load time?

jbms commented 2 years ago

Unfortunately there is not.

j6k4m8 commented 2 years ago

Got it, thank you for the quick response! Would our adding support for this be a useful contribution, or is it this way for a reason?

jbms commented 2 years ago

It hasn't exactly come up before. The segmentQuery layer property allows you to specify a query, but the user would still then need to actually select the segments included in the query.

Do you have a specific use case in mind where it would be difficult to just look up the actual id?

j6k4m8 commented 2 years ago

Got it! My proposed use cases would be something like:

All of this could be done by querying the properties json separately before rendering ngl state, so this is not blocking science :)