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

ENH: Bem editing? #3291

Closed
larsoner opened this issue Jun 8, 2016 · 19 comments
Closed

ENH: Bem editing? #3291

larsoner opened this issue Jun 8, 2016 · 19 comments

Comments

@larsoner
Copy link
Member

larsoner commented Jun 8, 2016

@kingjr recently asked (but is probably too wary of opening issues to do it):

is there a way to quickly edit BEMs? I have some intersections between inner and outer skulls but they're tiny, and a manual dragging of the points would really help.

My suggestion would be to:

  1. Find some nice triangulated mesh editing software (3D program of some sort, maybe CAD or blender?)
  2. Figure out what file format it needs
  3. Convert the surf to that format (it should be simple, if it's not, open MNE-Python issue and I'll help there)
  4. Document the process in the docs

Does anyone know of a better way? If not, then we can make a recommendation for how people can fix minor BEM surface issues if necessary.

@larsoner larsoner added this to the 0.13 milestone Jun 8, 2016
@kingjr
Copy link
Member

kingjr commented Jun 8, 2016

Relatedly, I am currently trying to see whether I can fix the tiny surface intersections problem by:

  • Detecting the points outside the outer surface (e.g. inner skull point out of outer skull)
  • Changing the xyz of these points by a param k toward the center of the surface

EDIT: in any case we'd need to wait for nipy/nibabel#458 to be merged.

@dgwakeman
Copy link
Contributor

  1. Make sure people know they should be using good quality MR sequences including MEFLASH if they have EEG
  2. If they just have MEG they should just use a single layer
  3. in lucky cases mne_surf2bem can shift the surfaces to avoid simple problems

@larsoner
Copy link
Member Author

larsoner commented Jun 8, 2016

@kingjr you know we have code for detecting whether points are inside a surface already right?

@kingjr
Copy link
Member

kingjr commented Jun 8, 2016

@Eric89GXL Yes, I'm now trying to understand how it works :)

@larsoner
Copy link
Member Author

larsoner commented Jun 8, 2016

Follow the trail of the surface topology checks in _check_surfaces

@dgwakeman
Copy link
Contributor

Seriously though, is there a problem with getting an MEFLASH or with mri_make_bem_surfaces (it has never failed for me)?

@kingjr
Copy link
Member

kingjr commented Jun 8, 2016

@dgwakeman It's not always possible to acquire MRI, sometimes you have to retrieve from archive data.

@kingjr
Copy link
Member

kingjr commented Jun 8, 2016

[i.e. you don't always have the adequate MRI sequence, hence the unstable segmentation]

@dgwakeman
Copy link
Contributor

dgwakeman commented Jun 8, 2016

Ok, in that case the one cheap easy step to solve the intersection problem with the watershed BEM is to just binarize and smooth/expand the 3d volume of the aseg volume from FreeSurfer, and then just fit an icosahedral surface to it. That should avoid all intersections. This would be totally automatable, and easy. I had some hacks to do this back in the day (hacking calls to mri_watershed: the code is pretty entrenched in a particular naming directory structure). Note, the watershed is still not recommended for EEG.

I did that to generate the inner skull surface for the SPM BEM. Then I did way crazier hacks to get the outer skull, but that is a ton of work.

@kingjr
Copy link
Member

kingjr commented Jun 8, 2016

@dgwakeman that seems like a better fix than what I was suggesting. Would you be ok sharing your script and opening a PR?

@dgwakeman
Copy link
Contributor

I can try to dig it up, but it doesn't really belong in mne-python (unless we got icosahedral meshing and I missed it), because it uses FreeSurfer commands. I'm happy to help. I'm in the middle of moving (to Philadelphia if anyone knows of labs looking for someone, or wants to hire a consultant to work remotely), but I should be able to look into it late next week. I'm setting an alarm now to look at it on Friday afternoon. hth d

@romquentin
Copy link

If I understand correctly, because I have only MEG data, I can only reconstruct a one layer bem model with
make_bem_model(subject, conductivity=[0.3], subjects_dir=subjects_dir) which will give me only the inner_skull surface?

@kingjr
Copy link
Member

kingjr commented Nov 23, 2016

yes, for meg you don't need 3 layers

On 23 November 2016 at 09:32, romquentin notifications@github.com wrote:

If I understand correctly, because I have only MEG data, I can only
reconstruct a one layer bem model with
make_bem_model(subject, conductivity=[0.3], subjects_dir=subjects_dir)
which will give me only the inner_skull surface?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#3291 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AEp7DLr8K4umOrbRCHCSkBhsPG2sEyyjks5rBE5_gaJpZM4Iw-2P
.

@romquentin
Copy link

Ok Thank you!
On some case, the inner skull miss a part of the brain so I would still need a tool to expand the inner skull surface...

@romquentin
Copy link

Specifically, this pattern is very common in my participants, with a surface error on the right frontal part...
screen shot 2016-11-23 at 10 02 32 am

@larsoner
Copy link
Member Author

larsoner commented Dec 5, 2017

Closing as I don't think there is much we can do in MNE to fix this, it's more of a Freesurfer / triangulated mesh problem (but feel free to comment further if people find other fixes)

@larsoner larsoner closed this as completed Dec 5, 2017
@nwilming
Copy link
Contributor

nwilming commented Mar 5, 2018

Maybe this is useful for future reference.

I had a similar problem to @romquentin, one of my outer skin meshes had fairly large holes on either side. This was actually pretty easy to fix using meshlab (http://www.meshlab.net/). This is what I did:

  1. Convert freesurfrer surfaces to e.g. stl format using mris_convert
  2. Open surface in meshlab
  3. In my case I selected the faces in my 'holes' using the selection tool, making sure to press 'alt' to only select visible faces.
  4. Delete offending faces
  5. Select 'Filters -> Remeshing, Simplification and Reconstruction -> Close holes'
  6. Export surface to stl file. Make sure to uncheck the 'Binary encoding' checkbox.
  7. Convert stl surface to freesurfer surface format using mris_convert.

This nicely filled the holes. Not sure how helpful meshlab is for other defects but is certainly worth a look.

@larsoner
Copy link
Member Author

larsoner commented Mar 5, 2018

@nwilming nice! It would be good to add this to the docs. We could either put it in the FAQ:

https://martinos.org/mne/stable/faq.html

Or here:

https://martinos.org/mne/stable/manual/source_localization/forward.html#topology-checks

The latter is a bit outdated / talks about MNE-C a lot. We should probably update it. But that wouldn't prevent us from adding this useful information there.

@ezemikulan
Copy link
Contributor

ezemikulan commented May 11, 2018

Hi, I've been trying different ways to edit the surfaces used for BEM. In my experience, converting to .stl format is not useful for further processing as it loses the vertex order information, which results in an error when creating the BEM model (mne.make_bem_model):

"RuntimeError: The source surface has a matching number of triangles but ordering is wrong". bem.py (line 361)

The way I found to edit the surfaces is:

  1. Convert from freesurfer surface to ascii (with freesurfer's mris_convert)
  2. Convert from ascii to .obj (using Brainder's functions)
  3. Edit in Blender (and export .obj)
  4. Convert from .obj to ascii (using Brainder's functions)
  5. Convert from ascii to freesurfer surface (with freesurfer's mris_convert)

I createad a small guide that shows how to do the edition in Blender and also some scripts to automatize the process of converting all the files created by mne.bem.make_watershed_bem.

I hope it will be useful!

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

6 participants