Skip to content

ENH: Volume labeling #6155

Closed
Closed

Description

@larsoner

At some point we should have a way of "label-izing" volumes like we do for surfaces. Freesurfer probably has utilities/files for this but I've never looked or worked with them (probably aseg.mgz), and in general we should have a way of making volume labels. Basically we need (API proposal):

  1. read_labels_from_aseg (or whatever the correct Freesurfer file is), which returns a list of...
  2. VolumeLabel or some equivalent (needs suitabl API and I/O functions)
  3. extract_label_time_course extended to work for VolSourecEstimate + VolLabel

Eventually we should make everything work for mixed source spaces, too, but there are probably other things to sort out before then (e.g., mixed orientation priors).

Activity

  1. self-assigned this
    on Apr 16, 2019
  2. agramfort commented on Apr 16, 2019

    @agramfort
    SponsorMember
  3. vferat commented on Aug 14, 2019

    @vferat
    Contributor

    Maybe the labeling of volume sources should be done during the creation of theSourceSpacesinstance. When using mne.setup_volume_source_space, setting the MRI value to the specific atlas you want ( such as aprac+aseg.mgz) should store labels for each source.
    This may be more consistent when setting the volume_label argument as labels from the mri file could be use to map the brain with sources.


    EDIT:
    by overwritting the _get_lut() function in mne.source_space

    def _get_lut():
        print("used")
        """Get the Custom LUT."""
        lut_fname = custom_LUT_filename
        dtype = [('id', '<i8'), ('name', 'U47'),
                 ('R', '<i8'), ('G', '<i8'), ('B', '<i8'), ('A', '<i8')]
        return np.genfromtxt(lut_fname, dtype=dtype)
    

    mne.source_space._get_lut = _get_lut
    where custom_LUT_filename is the path to my custom Look up table

    and then creating the source space:

    vol_src = mne.setup_volume_source_space(
        subject, mri=my_custom_parc, pos=5.0, bem=bem_model,
        volume_label=labels_vol, subjects_dir=subjects_dir)
    

    where my_custom_parc is my custom .mgz parcellation file and labels_vol are some labels found in this previous file, I was able to obtain a list of SourceEstimate corresponding to my custom labels.

    This may be a way to work with label for VolumeSources

  4. agramfort commented on Aug 16, 2019

    @agramfort
    SponsorMember
  5. vferat commented on Sep 9, 2019

    @vferat
    Contributor

    Logically, annotations and aseg files should share the same labels names.

    Shall we create a new class VolumeLabel or add an attribute to the existing one Label such as voxels.
    LabeL.voxels would be an array (n_voxels, 3) containing the x,y,z positions of each voxels belonging to the label ?
    Maybe another attribute such as LabeL.trans will be needed to store the vox2ras_tkr transformation and assign sources to label later.

    In extract_label_time_course we could check if a source belongs to a label by checking either Label.vertices if the source is a surface one or Label.voxels if the source is a VolSourecEstimate

  6. agramfort commented on Sep 9, 2019

    @agramfort
    SponsorMember

    to mimic the Label logic that is defined wrt the high resolution surface the VolumeLabel / VolLabel should be defined according to T1.mgz. I would have it use an attribute vertices (would avoid unnecessary branching I suspect) that would be a flat list if integers which corresponds to coordiantes in MRI 3d array after ravelling it to 1d. VolLabel would then be very close to Label API.

    my 2c

  7. added this to the 0.20 milestone on Sep 19, 2019
  8. larsoner commented on Oct 31, 2019

    @larsoner
    MemberAuthor

    See also closed #6278 where @ckiefer0 has some working scripts

  9. pshahbasak commented on Oct 31, 2019

    @pshahbasak

    Thanks @larsoner for directing me to this discussion. I think it will be useful to add options beyond taking the mean to extract time series within a cluster/parcel, like principal component analysis. What are your thoughts on using these other methods for extracting a 'representative' signal?

  10. 4 remaining items

  11. poojaprabhu9 commented on Feb 4, 2020

    @poojaprabhu9

    It will be of great help, if you can resolve this.
    Please.

  12. virvw commented on Feb 4, 2020

    @virvw
    Contributor

    Dear @larsoner @agramfort - is this something we could help achieve / make progress on or is it currently out of reach? (rather decisive in how to finalize a study for @poojaprabhu9 hence her plea ;-)

  13. larsoner commented on Feb 5, 2020

    @larsoner
    MemberAuthor

    It might take a bit of API design and work to get right. I'm not sure when I'd get to it (not in the next week or two probably).

    One concrete step that might work is making extract_label_time_course deal with the Vector* variants of SourceEstimates work properly (probably just with 'mean' mode). That way volume and other free orientation source estimates could be processed properly.

    Then we could decide on a way to encode volume information properly. In the meantime here is some code that I wrote to take an atlas (in the same space as the subject) and give a binary mask for the voxels of interest:

    https://gist.github.com/larsoner/a2be47b0489ac04834f67c883cc4d6c2

    It contains specialized code for atlases/subjects, but hopefully it at least gives you something to use to code your own extractor. This plus the scripts from #6278 hopefully will give a start...

  14. modified the milestones: 0.20, 0.21 on Mar 4, 2020
  15. larsoner commented on Apr 10, 2020

    @larsoner
    MemberAuthor

    I'm wondering if the idea of creating volume labels like we currently have for surfaces is overkill/not so useful. I had a brainstorming session with @agramfort and a simpler API (to implement and use, I think) would be:

    • vol_stc.in_label(atlas, idx, src) where for example you could do:
      aparc, lut = mne.read_freesurfer_volume_atlas(
          'aparc.a2009s+aseg.mgz', subject, subjects_dir)
      vol_stc.in_label(aparc, lut['ctx-lh-transversetemporal'], src)
      
      or with your own custom atlas in the subject's space:
      vol_stc.in_label(custom_atlas, idx, src)
      
    • extract_label_time_course(vol_stc, atlas, src) to obtain an ndarray of shape (n_rois, n_times)

    Advantages:

    • remains pretty readable within the Freesurfer context by allowing us to load an atlas for the given subject (along with the lookup table for region to atlas values)
    • simultaneously allows atlas to be a generic SpatialImage (or str path to something nib.load-able) that must be in the subject's MRI space with arbitrary idx numbers.
    • stays closer to the MRI world when working with the data, which should help integration with other packages, etc.

    One potential disadvantage is that it puts the onus on the user to transform their atlas to the subject space if it isn't already there, but there are nice tools for this already outside of MNE I think, and it's not really in scope for our package (or sustainable for us) to do so.

    Once simple mean over the labels is done, we can extend to other methods (like pca).

    @virvw @poojaprabhu9 @vferat @pshahbasak @ckiefer0 WDYT? Also @britta-wstnr I think you work on volumetric data and hence might be interested in this

  16. larsoner commented on Apr 10, 2020

    @larsoner
    MemberAuthor

    @vferat this sort of thing can also be ported over to setup_volume_source_estimate if you do want to make custom MixedSourceEstimates with surface cortical + volume subcortical spaces, for example (see also #7597)

  17. vferat commented on Apr 11, 2020

    @vferat
    Contributor

    Seems alright for me:
    Maybe add a generic public function to read freesurfer luts that may not be distributed with freesurfer ( here an exemple with Schaefer atlas):

    aparc = nib.load(aparc_Schaefer2018_100Parcels_17Networks.mgz)
    lut = mne.read_freesurfer_lut( Schaefer2018_100Parcels_17Networks_LUT.txt)
    vol_stc.in_label(aparc, lut['17Networks_LH_LimbicA_TempPole_1'],  src)
    

    Also this may requieres to add support for VolSourceEstimate to extract_label_time_course (so far the first 2 source spaces have to be surf type ) if we want to be able to extract tc for Volume sources only. (I'm not sure it's on the scope of MNE)

    Modifying setup_volume_source_estimate , should be as simple as adding an input name 'lut' with default value targetting the freesurfer default LUT. A combination of custom volume_label and custom 'lut' will allow user to used custom atlas.

  18. larsoner commented on Apr 11, 2020

    @larsoner
    MemberAuthor

    Maybe add a generic public function to read freesurfer luts

    Good idea, I think we have it privately already, we could make it public as part of this.

    Also this may requieres to add support for VolSourceEstimate to extract_label_time_course (so far the first 2 source spaces have to be surf type ) if we want to be able to extract tc for Volume sources only. (I'm not sure it's on the scope of MNE)

    Indeed, this is (implicitly) part of #7597

    Modifying setup_volume_source_estimate , should be as simple as adding an input name 'lut' with default value targetting the freesurfer default LUT. A combination of custom volume_label and custom 'lut' will allow user to used custom atlas.

    Would this be helpful for you?

  19. vferat commented on Apr 13, 2020

    @vferat
    Contributor

    Would this be helpful for you?

    Yes, I think it's necessary if people want to use only volume sources, and reject some region such as cerebellar white matter or other unwanted region (optic chiams ect..)

    I don't know how much work it is, but I could be interesting to use a include / exclude API instead of volume_label for creating the volume source space. These two mutually exclusive arguments, either list of int or list of string will allow user to pick region by value in the MRI, or name in the lut.

    While working with Mixed source space, extract_label_time_course may take both atlas and labels arguments. If the 2 first source spaces are no longer of type Surf, and/or there are no sources in some volume vol_stc.in_label, time courses order could be confusing. I suggest returning the regions names (list of string) to prevent a lot of errors (by adding an input return_names=False for backward compatibility.

    Let me know if you think it's worth, and if you need some help to work on it.

  20. larsoner commented on Apr 13, 2020

    @larsoner
    MemberAuthor

    I don't know how much work it is, but I could be interesting to use a include / exclude API instead of volume_label for creating the volume source space.

    I'll have to think on this one, and how it interacts with volume_label. It seems like at least a mostly separable issue, can you open a new issue to describe the use case and your proposed API? That way we can tackle it separately and not lose track of it.

    If the 2 first source spaces are no longer of type Surf, and/or there are no sources in some volume vol_stc.in_label, time courses order could be confusing.

    We already have an allow_empty kwarg for extract_label_time_course. We should do whatever it does for surface source space labels when there are no source vertices corresponding to a given ROI, then there is no need for a new argument or return value and we stay internally consistent.

  21. larsoner commented on Apr 24, 2020

    @larsoner
    MemberAuthor

    FYI I have an implementation based on the discussions above in #7639. Feel free to have a look at the API and try it out!

  22. poojaprabhu9 commented on Apr 24, 2020

    @poojaprabhu9
  23. larsoner commented on Apr 25, 2020

    @larsoner
    MemberAuthor

    Should now be fixed in the PR (let's keep conversation there for now)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions