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

text labels for segmentation layer #199

Closed
d-v-b opened this issue Feb 14, 2020 · 24 comments
Closed

text labels for segmentation layer #199

d-v-b opened this issue Feb 14, 2020 · 24 comments

Comments

@d-v-b
Copy link
Contributor

d-v-b commented Feb 14, 2020

Is it possible to construct a segmentation layer with a mapping that assigns a name to each unique value in the underlying data?

@jbms
Copy link
Collaborator

jbms commented Feb 14, 2020

Yes, via a segment property map defined using the precomputed format:

https://github.com/google/neuroglancer/blob/master/src/neuroglancer/datasource/precomputed/segment_properties.md

See example here:
https://hemibrain-dot-neuroglancer-demo.appspot.com/#!gs://neuroglancer-janelia-flyem-hemibrain/v1.0/neuroglancer_demo_states/base.json

Note: The segmentation data itself does not need to be in the neuroglancer precomputed format, you can just add the segment property map as an additional data source.

@jbms
Copy link
Collaborator

jbms commented Feb 14, 2020

Note: Ignore the "indexed" property type, that isn't implemented yet.

@jbms
Copy link
Collaborator

jbms commented Feb 15, 2020

Depending on your use case, it might also make sense to define a new segment property map data source type, e.g. a DVID-backed one.

@d-v-b
Copy link
Contributor Author

d-v-b commented Feb 15, 2020

Thanks for the information, I'm not sure I grok it all yet. For context, my datasets are n5 arrays stored on s3. I will have between 0 and 60 text labels to map to the same number of integer values in the segmented volume.

Are you saying that I would need to define a segment property map as a datasource backed by a new JSON file that contains the mapping between uint64 values in one of my segmented volumes? (I know the FlyEM team, so I can ask them about this if you think they can demonstrate this to me)

@jbms
Copy link
Collaborator

jbms commented Feb 15, 2020

Yes, create a JSON file like:

https://neuroglancer-janelia-flyem-hemibrain.storage.googleapis.com/v1.0/rois/segment_properties/info

Then make sure it can be retrieved via a URL like:
https://whatever/path/info

(the filename must be info)

then add as a data source:

precomputed://https://whatever

If there is some convention for defining such maps as additional attributes within the n5 attributes.json file, then it would be easy enough to add support to Neuroglancer for that as well (then the map could be used automatically when you add the n5 data source).

@austinhoag
Copy link
Contributor

@jbms what is your suggested method for hosting the segment properties JSON file? I only know about hosting precomputed datasets with cloudvolume, but since this info file is not of the right format for cloudvolume, then that is not an option.

@jbms
Copy link
Collaborator

jbms commented May 4, 2020

You will have to write your own code to generate it, but that should be easy since the format is pretty simple. If you are using Google Cloud Storage, you can upload it using gsutil or with one the Python libraries (e.g. boto or https://cloud.google.com/storage/docs/reference/libraries).

@jbms jbms closed this as completed May 4, 2020
@austinhoag
Copy link
Contributor

austinhoag commented May 4, 2020

My solution needs to be local - in my project we are hosting our data locally rather than in the cloud. I wrote my own code to host the info file locally using flask, but Neuroglancer gives me a CORS error:
Fetching "http://localhost:5005/info" resulted in HTTP error 0: Network or CORS error. I verified that curl http://localhost:5005/info does give me the json body. I find the error surprising because I can successfully use cloudvolumes in Neuroglancer that are hosted locally and without https. I should also mention that I am running neuroglancer locally.

@jbms
Copy link
Collaborator

jbms commented May 4, 2020

Using a local web server is fine, but you will need to set it up to send back the appropriate CORS headers. I'm not sure specifically how to set that up with flask (though I did find this https://flask-cors.readthedocs.io/en/latest/). As an example, you can use cors_webserver.py in the neuroglancer repository, or the node http-server package with the --cors option.

@austinhoag
Copy link
Contributor

OK that worked in the sense that I no longer get a CORS error and can load in localhost:5000 as a layer with no errors. However, I don't see any segment property information showing up in my segmentation layer under the "Seg." tab. I have tried the example info file you referenced above and another one, but still no luck. I figured the problem with the example info file was that there was no "string" type property, so I added one in my example but that did not help. Is there an extra step required that I am missing? Here is the example info file I have tried in addition to the one referenced above:
{"@type": "neuroglancer_segment_properties", "inline": {"ids": ["1"], "properties": [{"id": "string", "type": "string", "values": ["AB(L)"]},{"id": "label", "type": "label", "values": ["AB(L)"]},{"id": "description", "type": "description", "values": ["AB(L)"]}]}}

@austinhoag
Copy link
Contributor

@d-v-b did you end up getting this working with a separate info JSON file defining the segment properties?

@manoaman
Copy link

manoaman commented Dec 4, 2020

Yes, via a segment property map defined using the precomputed format:

https://github.com/google/neuroglancer/blob/master/src/neuroglancer/datasource/precomputed/segment_properties.md

See example here:
https://hemibrain-dot-neuroglancer-demo.appspot.com/#!gs://neuroglancer-janelia-flyem-hemibrain/v1.0/neuroglancer_demo_states/base.json

Note: The segmentation data itself does not need to be in the neuroglancer precomputed format, you can just add the segment property map as an additional data source.

Is there a template or an accessible example of base.json for segmentation properties? I suppose gs://neuroglancer-janelia-flyem-hemibrain/v1.0/neuroglancer_demo_states/base.json is not accessible?

@jbms
Copy link
Collaborator

jbms commented Dec 4, 2020

The base.json file is accessible, but it is just a Neuroglancer state:
https://storage.googleapis.com/neuroglancer-janelia-flyem-hemibrain/v1.0/neuroglancer_demo_states/base.json

Add a segment_properties member to the the info file for the segmentation:
http://storage.googleapis.com/neuroglancer-janelia-flyem-hemibrain/v1.0/rois/info

The value is the name of the sub-directory.

Then create the info file in the sub-directory specified by the segment_property key:

http://storage.googleapis.com/neuroglancer-janelia-flyem-hemibrain/v1.0/rois/segment_properties/info

@jbms
Copy link
Collaborator

jbms commented Dec 4, 2020

@austinhoag I missed your comment earlier, but the additional step required for the segment properties to show up in the data source list is to reference it from your top-level info file via a "segment_properties" member. See example in prior message. You can also directly add the segment_properties as an additional data source to the layer, using the "+" button at the button of the Sources tab.

@manoaman
Copy link

manoaman commented Dec 9, 2020

The base.json file is accessible, but it is just a Neuroglancer state:
https://storage.googleapis.com/neuroglancer-janelia-flyem-hemibrain/v1.0/neuroglancer_demo_states/base.json

Add a segment_properties member to the the info file for the segmentation:
http://storage.googleapis.com/neuroglancer-janelia-flyem-hemibrain/v1.0/rois/info

The value is the name of the sub-directory.

Then create the info file in the sub-directory specified by the segment_property key:

http://storage.googleapis.com/neuroglancer-janelia-flyem-hemibrain/v1.0/rois/segment_properties/info

@jbms I can't seem to load up "segment_properties" even after I created the sub-directory and info file. And I have doubts where I'm placing the "segment_name_map": "names", "segment_property": "segment_properties" since they disappear after I apply the change to json on Neuroglancer. (When I load this sub directory as a main source, I do see segmentation ids in the tab without the actual data.) Would you be able to point out what I'm doing wrong here? Thanks, -m

{
  "dimensions": {
    "x": [
      0.000025,
      "m"
    ],
    "y": [
      0.000025,
      "m"
    ],
    "z": [
      0.000025,
      "m"
    ]
  },
  "position": [
    240.36245727539062,
    170.15975952148438,
    0.5
  ],
  "crossSectionScale": 1.055028746424448,
  "crossSectionDepth": -5,
  "projectionOrientation": [
    0.20196738839149475,
    0.7169978022575378,
    -0.618348240852356,
    -0.25053688883781433
  ],
  "projectionScale": 82.81277574512146,
  "layers": [
    {
      "type": "segmentation",
      "source": [
        "precomputed://http://localhost:8888/precomputed/test_data",
        "mesh"
      ],
      "tab": "segments",
      "name": "segmented mesh",
      "segment_name_map": "names",      ----> (disappears)
      "segment_property": "segment_properties"   ----> (disappears)
    }
  ],
  "showSlices": false,
  "gpuMemoryLimit": 4000000000,
  "systemMemoryLimit": 4000000000,
  "selectedLayer": {
    "layer": "segmented mesh",
    "visible": true,
    "size": 290
  },
  "layout": "4panel",
  "statistics": {
    "size": 309
  }
}

@jbms
Copy link
Collaborator

jbms commented Dec 9, 2020

segment_name_map is a remnant for an earlier version of the support in Neuroglancer. Don't use that, just use "segment_properties".

segment_properties is not a property to be specified in the Neuroglancer JSON state (what you've posted above). It is a property to set in the info file. However, if you have your segment_properties info file available at:

http://localhost:8888/precomputed/test_data/segment_properties/info

Then if you don't want to add the segment_properties property to your test_data/info file, you can instead add:

precomputed://http://localhost:8888/precomputed/test_data/segment_properties

as an additional data source to the same layer in the Neuroglancer JSON state:

...
  "layers": [
    {
      "type": "segmentation",
      "source": [
        "precomputed://http://localhost:8888/precomputed/test_data",
        "precomputed://http://localhost:8888/precomputed/test_data/segment_properties",
      ],
      "tab": "segments",
      "name": "segmented mesh",
    }
  ],
...

You can also add additional data sources in the UI:
image

@manoaman
Copy link

segment_name_map is a remnant for an earlier version of the support in Neuroglancer. Don't use that, just use "segment_properties".

segment_properties is not a property to be specified in the Neuroglancer JSON state (what you've posted above). It is a property to set in the info file. However, if you have your segment_properties info file available at:

http://localhost:8888/precomputed/test_data/segment_properties/info

Then if you don't want to add the segment_properties property to your test_data/info file, you can instead add:

precomputed://http://localhost:8888/precomputed/test_data/segment_properties

as an additional data source to the same layer in the Neuroglancer JSON state:

...
  "layers": [
    {
      "type": "segmentation",
      "source": [
        "precomputed://http://localhost:8888/precomputed/test_data",
        "precomputed://http://localhost:8888/precomputed/test_data/segment_properties",
      ],
      "tab": "segments",
      "name": "segmented mesh",
    }
  ],
...

You can also add additional data sources in the UI:
image

That works great! Thanks @jbms Could I also ask how to open and use the bottom "select" UI? I suppose it is to select coordinates in the viewer and pin to the dashboard? I have not figured out the "Annotations" tab yet so I suppose it might be used for just picking a point versus cropping a volume in "Annotations" tab?

Thank you always for your help @jbms
-m

Screen Shot 2020-12-09 at 4 40 16 PM

@jbms
Copy link
Collaborator

jbms commented Dec 10, 2020

Control right-click opens that panel.

@manoaman
Copy link

manoaman commented Dec 10, 2020

Agh, I see. I had to use a mouse instead of the track pad. My track pad on mac keeps getting the following warning and I wasn't sure how to activate this. Could I activate annotation tool without mouse? But mouse right click seem to pop up the gui ok. Thank you @jbms

Screen Shot 2020-12-10 at 9 17 38 AM

@jbms
Copy link
Collaborator

jbms commented Dec 10, 2020

Thanks for pointing out the issue with using control+rightclick on macOS. I think the issue is that macOS converts rightclick to control+click and vice versa in some cases, because historically Apple shipped machines with just a single button mouse. It appears that control+rightclick is getting translated to just control+leftclick, which is the annotate action. I will have to look into an alternative binding that works on macOS. Or perhaps you can check if there is already a way to trigger control+rightclick from the touchpad?

@manoaman
Copy link

I figured "control + two fingers" on the trackpad and that seem to pop up the GUI so I suppose that could work?

@manoaman
Copy link

Sorry, I had to ask this @jbms Does segment_properties support color attribute to assign fixed color code on each segmentation? l key works great to reassign colors on each mesh but I was wondering if that is already supported.

Thanks, -m

https://github.com/google/neuroglancer/blob/master/src/neuroglancer/datasource/precomputed/segment_properties.md

@jbms
Copy link
Collaborator

jbms commented Dec 10, 2020

To be clear, control + two finger click already works on your trackpad? If I get around to writing documentation, I'll include that.

Currently setting colors via precomputed segment_properties is not supported, but that would certainly make sense as a feature if you were interested in implementing it. At the moment you can only assign colors using the segmentColors property of a segmentation layer in the Neuroglancer JSON state.

@manoaman
Copy link

yes, I've given a try and control + two finger click does work on my trackpad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants