Computer graphics (CG) applications, such as Blender, Maya or 3D Studio, doesn’t come with filters that allow to directly import or export FreeSurfer meshes. To import brain surfaces to these applications, converting first to an intermediate file format solves the problem. Below is an example of a brain imported into Blender.
The mris_convert, from FreeSurfer, allows conversion to stereolithography format (STL). However, not all CG applications read natively from STL files. Moreover, other formats, such as Wavefront OBJ and Stanford PLY have simpler structure — yet allowing features that will be discussed here in forthcoming articles.
Conversion from FreeSurfer to Wavefront OBJ
A simple procedure to convert a FreeSurfer surface to Wavefront OBJ (ASCII) is:
1) Use mris_convert to convert from FreeSurfer binary to ASCII:
mris_convert lh.pial lh.pial.asc
2) A suggestion is to rename the .asc file to .srf, to differentiate it from other files that also have .asc extension and have a different internal structure.
mv lh.pial.asc lh.pial.srf
3) Use the script srf2obj to convert from .srf to .asc:
srf2obj lh.pial.srf > lh.pial.obj
The symbol “>” is necessary so that the output from srf2obj is redirected to a new file.
Conversion from Wavefront OBJ to FreeSurfer
To convert back to FreeSurfer, a similar strategy is used.
1) Use the script obj2srf to generate new .srf files (here directly named as .asc, as expected by mris_convert)
obj2srf lh.pial.obj > lh.pial.asc
2) Use mris_convert:
mris_convert lh.pial.asc lh.pial
The scripts use gawk as the interpreter, and expects to find it on its usual location (/bin/gawk). If in your system gawk is installed elsewhere, modify the first line accordingly.
If you don’t have gawk, you can get it from the repository of your Linux distribution. For Mac, gawk is available in MacPorts and Fink. Alternatively, you may replace gawk with awk itself, nawk, or any other awk implementation that works.