Skip to content

ENH: Use something other than FreeSurfer for BEM extraction #7232

Open

Description

@Davi1990

Dear MNE expert,

I am working with a EEG dataset and I wish to run source on that. Unfortunately the T1w are not FLASH and I know that in the absence of FLASH images, MNE offers a somewhat less accurate
solution based on the watershed algorithm (see Jas et al., 2018).

Indeed for some subjects in my dataset (see attached 1) I got the following error when I am going to run make_bem_model.

RuntimeError: Surface inner skull is not completely inside surface outer skull

For other subject instead the surfaces are simply wrong (see attached 2), even though make_bem_model hadn't give me any error

Screen Shot 2020-01-20 at 14 13 39

Screen Shot 2020-01-20 at 14 13 04

I was wondering whether if you have some tips on how to fix them.

Thanks

Dave

Activity

  1. jasmainak commented on Jan 21, 2020

    @jasmainak
    Member

    @Davi1990 it's better to report these in the mailing list. Unless you are sure it's a bug, I recommend asking there. You can also search the archives and find that similar issues were already answered:

    https://mail.nmr.mgh.harvard.edu/pipermail//mne_analysis/2019-April/005805.html
    https://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/2019-November/006317.html

    hope that helps

  2. Davi1990 commented on Jan 21, 2020

    @Davi1990
    Author

    Hi @jasmainak!! I posted few weeks ago but I haven't received any reply message. I am going to ask again right now. I am deadlocked!

    Hope to receive some helps this time

    Dave

  3. Davi1990 commented on Jan 28, 2020

    @Davi1990
    Author

    Hi @jasmainak!!

    Thanks for your reply. Unfortunately I already saw the question that you posted.

    I have done some work on the surfaces trying to get the best result possible.

    image

    This looks reasonable to me but I would like to listen your opinion on that. I don't understand why the surfaces are not registered with the main T1w though.

    Moreover, when I am reconstructing the bem model in MNE I got the following error:

    "Cannot decimate to requested ico grade 4. The provided BEM surface has 78784 triangles, which cannot be isomorphic with a subdivided icosahedron. Consider manually decimating the surface to a suitable density and then use ico=None in make_bem_model"

    Maybe the meshes have too many triangles so I need to down sample the vertices to below 10000....

    Any tips would be highly appreciate

    Thanks

  4. larsoner commented on Jan 28, 2020

    @larsoner
    Member

    This looks reasonable to me but I would like to listen your opinion on that. I don't understand why the surfaces are not registered with the main T1w though.

    How did you make this plot? If you aren't using mne.viz.plot_bem or freeview in Freesurfer, it's likely that the plotting is wrong because of MRI surface RAS coordinates versus standard RAS/affine that other software might use.

  5. larsoner commented on Jan 28, 2020

    @larsoner
    Member

    Regarding the number of vertices, #7259 will probably / hopefully have some solutions for suitable decimation

  6. Davi1990 commented on Jan 28, 2020

    @Davi1990
    Author

    @larsoner thanks for your suggestions. As for the number of vertices I am gonna try this once I have all the surfaces registered and I'll let you know

    As for the visualization, I've used freeview

  7. larsoner commented on Jan 28, 2020

    @larsoner
    Member

    Your surfaces in the first post are properly coregistered. How are they different from the ones in your more recent post? Differences in processing these surfaces probably gave rise to the alignment mismatch.

    For ideas on how to fix meshes, the ideas we have were recently consolidated here:

    https://mne.tools/dev/overview/faq.html#my-watershed-bem-meshes-look-incorrect

  8. Davi1990 commented on Jan 29, 2020

    @Davi1990
    Author

    I have worked in putting down a script that use different tools and in the end the surfaces right now are nicely coregistered with the T1w (see attached). Even though the outer skin is going a little bit outside but it should not be a big deal.

    Screen Shot 2020-01-29 at 11 04 23

    Anyway now I was trying to import them in MNE reconstructing the bem model in MNE I got the same error than before:

    "Cannot decimate to requested ico grade 4. The provided BEM surface has 78784 triangles, which cannot be isomorphic with a subdivided icosahedron. Consider manually decimating the surface to a suitable density and then use ico=None in make_bem_model"

    @larsoner I saw your suggestions but I wasn't able to find a solution and any other idea would be highly appreciated

    Thanks

  9. larsoner commented on Jan 29, 2020

    @larsoner
    Member

    Did you see this above?

    Regarding the number of vertices, #7259 will probably / hopefully have some solutions for suitable decimation

    In particular this comment has some code you could use to decimate your surface. Soon it will be adapted to mne.decimate_surface because it seems to be a necessary use case.

  10. larsoner commented on Jan 30, 2020

    @larsoner
    Member

    @christian-oreilly this issue makes me think that we might want to make the BEM mesh extraction we discussed more publicly available. If it takes hours then just some description in our FAQ would be good. If it takes about a minute then we should turn it into an example.

    Would you be able to make a PR for this? If you don't have time but have a notebook / some code to share with the marching cubes plus smoothing approach, I can see if either of these of these documentation ideas make sense

  11. christian-oreilly commented on Jan 30, 2020

    @christian-oreilly
    Contributor

    @larsoner You mean to document the cube marching + laplacian smoothing + decimation approach and the FS tessellation approach? I should be able at least to provide an initial PR. What often ends up taking longer for me is debugging the CI stuff and editing to adjust for project specific standards on naming and format that I am not familiar with. I will be happy to provide the PR, but will be happy to have a bit of help to push it through if it drags on these latter topics. Hopefully, these things will get smoother as I gain a bit of experience with contributing code to MNE...

  12. larsoner commented on Jan 30, 2020

    @larsoner
    Member

    Sounds good, I can help with the pedantic parts

  13. Davi1990 commented on Jan 30, 2020

    @Davi1990
    Author

    @larsoner yes I saw your comment above. I've run mne.decimate_surface so that the new surfaces have the same number of faces and vertices of the original. However I still get the same error.

    Moreover if I run the make_bem_model command with ico=None I got the following error instead:

    Surface outer skin has topological defects

    Sorry but this issue is keeping me stuck

  14. jasmainak commented on Jan 30, 2020

    @jasmainak
    Member

    @Davi1990 you have to play around with the Freesurfer commands until you get better surfaces. Alternatively you can also edit the surfaces manually. There are demos online: https://www.youtube.com/watch?v=AR83_Bt04VQ

  15. larsoner commented on Apr 7, 2020

    @larsoner
    Member

    @christian-oreilly any chance to make a WIP PR with the Python solution for creating BEM surfaces? I'm happy to take over once there is something that more or less works.

  16. 11 remaining items

  17. changed the title [-]Inconsistent surfaces extracted using watershed[/-] [+]ENH: Use something other than FreeSurfer for BEM extraction[/+] on Jan 7, 2021
  18. larsoner commented on Jan 11, 2021

    @larsoner
    Member

    @Davi1990 in your image above how did you get those three surfaces? From @christian-oreilly's code it's clear that we can go from a binarized/labeled MRI to usable suitably smooth surfaces, but he started from MRI data that was already labeled with each compartment. I'm curious how you got your compartment definitions and (of secondary importance) then turned them into surfaces.

  19. larsoner commented on Feb 3, 2021

    @larsoner
    Member

    Some exploration so far -- I've had decent luck with FieldTrip + SPM (worked on 157/158 subjects), but this requires MATLAB so it's a bit of a no-go.

    I then tried brainsuite and fsl using this gist. brainsuite skullfinder is very fast (1-2 sec) but produces a questionable output, whereas fsl seems to work well in about a minute of run-time.

    Subject 1

    brainsuite skullfinder:

    $ freeview -v T1.mgz -f bs_inner_skull.surf:edgecolor=red -f bs_outer_skull.surf:edgecolor=yellow -f bs_outer_skin.surf:edgecolor=255,170,128:hide_in_3d=true
    

    Screenshot from 2021-02-03 15-19-49

    fsl bet:

    Screenshot from 2021-02-03 15-43-51

    FieldTrip + SPM could not process this subject because it couldn't determine the orientation (the head is tilted about the Z axis is probably the issue?).

    Subject 2

    brainsuite:

    Screenshot from 2021-02-03 15-53-10

    fsl:

    Screenshot from 2021-02-03 15-52-34

    FieldTrip + SPM + Python mesh code to marching_cubes + smooth + decimate:

    Screenshot from 2021-02-03 15-49-26

    Overall I think I like the idea of adding a mne fsl_bem function that uses fsl to generate BEM surfaces. It already puts out ones that are smoothed and 5120 triangles, writes to a standard format (vtk) that can by read by pyvista, etc. It even makes sure that the meshes don't intersect:

    the mesh is self-intersecting 
    thus will rerun with higher smoothness constraint
    
  20. hoechenberger commented on Feb 4, 2021

    @hoechenberger
    Member

    Amazing work, @larsoner!! Would very much love to see this added to MNE

  21. modified the milestones: 0.23, 0.24 on Apr 19, 2021
  22. modified the milestones: 0.24, 1.0 on Oct 22, 2021
  23. modified the milestones: 1.0, 1.1 on Feb 11, 2022
  24. modified the milestones: 1.1, 1.2 on Jun 4, 2022
  25. modified the milestones: 1.2, 1.3 on Sep 13, 2022
  26. removed this from the 1.3 milestone on Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions