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.
- Convert surfaces from freesurfer format to ascii
- Convert from ascii to .obj format
- Edit in Blender
- Convert from .obj to ascii
- Convert from ascii to freesurfer format
- Freesurfer
- Surfaces (e.g. from mne.bem.make_watershed_bem)
- Brainder's conversion functions (srf2obj and obj2srf)
- Blender
- (Using a mouse will make the edition in Blender easier)
Please refer to each package's website for specific instructions.
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:
- Subjects name in freesurfer's subjects directory
- Path to freesurfer's subjects directory
- 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
We will import the surfaces in Blender, make the changes we need, and then export the new mesh in .obj format.
-
Open Blender.
-
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):
-
Repeat for all surfaces you want to import (e.g. inner_skull and outer_skull)
-
Zoom out using the mouse wheel:
-
Click on the plus sign on the top right corner of the 3D view :
-
Go to Display and set scale to 10. You can also make the grid invisible by unchecking Grid Floor:
You can toggle the visibility of an object from the Outliner panel :
To rotate the view click the mouse wheel and drag.
-
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:
-
in Edit Mode, right click one of the vertices that you want to correct in order to deselect all and select a single vertex.
-
Press the C key to activate the Circle Select tool (or B for Box Select). You can enlarge the area using the mouse wheel.
-
Use the left click to select the vertices you want to edit. You can click multiple times or click and drag:
- 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):
- 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 :
Make sure to have the Selecttion Only and Keep Vertex Order options turned on.
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)