Skip to content

ezemikulan/blender_freesurfer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blender and Freesurfer

Editing freesurfer surfaces in Blender for BEM modeling

Sometimes when creating a BEM model the surfaces need manual correction because of a series of problems that can arise (e.g. intersection between surfaces). Here, we will see how this can be achieved in Blender.

Steps

  1. Convert surfaces from freesurfer format to ascii
  2. Convert from ascii to .obj format
  3. Edit in Blender
  4. Convert from .obj to ascii
  5. Convert from ascii to freesurfer format

What do you need?

Installation

Please refer to each package's website for specific instructions.

1 & 2. From freesurfer to .obj

We will transform the surfaces to .obj so that they can be imported in Blender. In order to do this we will use Brainder's conversion functions. First we have to go from freesurfer to ascii and then from ascii to .obj format. This can be done manually (e.g. entering the commands in a terminal) or using the bash script to_blender.sh, which will do the conversion for all the surfaces created by mne.bem.make_watershed_bem. For instructions on how to do it manually see Brainder's. If you do it manually, make sure to create a backup of the original freesurfer surfaces.

The script to_blender.sh takes 3 arguments:

  1. Subjects name in freesurfer's subjects directory
  2. Path to freesurfer's subjects directory
  3. Path to the directory where Brainder's functions are located

To run the script, open a Terminal, go the folder where it is located, and excecute the following:

foo@bar:~$ ./to_blender.sh subj_name /path/to/freesurfer/subjects/directory /path/to/Brainder/functions

It will create a folder named conv inside the bem/watershed folder of the freesurfer subject, which will contain:

  • Backups of the original surfaces
  • Surfaces in ascii format
  • Surfaces in .obj format

NOTE: you might need to give excecution permission to the scripts in order to be able to run them:

foo@bar:~$ chmod +x to_blender.sh

3. Edit in Blender

We will import the surfaces in Blender, make the changes we need, and then export the new mesh in .obj format.

  1. Open Blender.

  2. Go to File > Import > Wavefront (.obj). Navigate to the conv folder and select the file you want to import. Make sure to select the Keep Vert Order option. You can also select the Y Forward option to load the axes in the correct direction (RAS):

alt text alt text

  1. Repeat for all surfaces you want to import (e.g. inner_skull and outer_skull)

  2. Zoom out using the mouse wheel:

  3. Click on the plus sign on the top right corner of the 3D view :

alt text

  1. Go to Display and set scale to 10. You can also make the grid invisible by unchecking Grid Floor:

    alt text

    You can toggle the visibility of an object from the Outliner panel :

    alt text

    To rotate the view click the mouse wheel and drag.

  2. Find the vertices you need to edit. It is useful to select the inner surface and go to the Edit Mode. This will highlight all the vertices and edges of the inner surface. If there are vertices that are outside of the outer surface you should be able to see them:

alt text

  1. in Edit Mode, right click one of the vertices that you want to correct in order to deselect all and select a single vertex.

  2. Press the C key to activate the Circle Select tool (or B for Box Select). You can enlarge the area using the mouse wheel.

  3. Use the left click to select the vertices you want to edit. You can click multiple times or click and drag:

alt text alt text

  1. Rotate the view to a good angle and use the arrows to edit the position of the selected vertices. There are many other (and more advanced) ways to perform the corrections (see for example Loop Tools or Face Tools):

alt text

  1. Select the edited object in the Outliner panel (if it is not already selected). Go to File > Export > Wavefront (.obj). Navigate to the conv folder. Add _edit to the .obj file's original name (e.g. subj_name_inner_skull_surface.obj -> subj_name_inner_skull_surface_edit.obj). Set the options as follows and export :

alt text

Make sure to have the Selecttion Only and Keep Vertex Order options turned on.

4 & 5. From .obj to freesurfer

We will finally convert the edited meshes to freesurfer format. First we will go from .obj to ascii and then from ascii to freesurfer surface. Again, you can do this manually, or use the script from_blender.sh. The script takes the same input parameters as to_blender.sh. It will create a new freesurfer surface that will end in _edit for all the files that have the _edit.obj suffix. Then you can manually copy the files to the watershed folder (where the original files were located) and rename them as the original files. This step is done manually because it implies overwriting the original surfaces (or having new files that have the same names as the original surfaces) and therefore it is better to do it when you are sure. Remember that to_blender.sh created backups of the original files so you can restore them when you want.

foo@bar:~$ ./from_blender.sh subj_name /path/to/freesurfer/subjects/directory /path/to/Brainder/functions

That's it. You are ready to continue with your analysis pipeline (e.g. running mne.make_bem_model)

About

Edition of freesurfer surfaces in Blender

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages