Moving arbitrary surface-data files from FreeSurfer to Brainstorm and back

Hello,

I am working on a project which involves extensively comparing MRI and (source-localized) MEG measurements. We have a number of files containing surface data for a Brainstorm subject; I can convert them into whatever format is most useful, but they store the same kind of data as, for example, FreeSurfer’s lh.curv: i.e., one number per FreeSurfer vertex for a single hemisphere. I would like to be able to import these into Brainstorm (to resample them onto my Brainstorm subject’s down-sampled surface) and to export Brainstorm data to a similar format. The Brainstorm subject was imported from FreeSurfer. Ideally I would also like to be able to visualize these in Brainstorm if possible, but I absolutely need to be able to easily move data from a Brainstorm surface to a FreeSurfer surface and back.

So far I haven’t found any way to do this that doesn’t involve re-importing the entire subject; since we will be moving data back and forth between the formats extensively, this isn’t a practical solution. I’m willing to do some coding to make this easier, and it seems like Brainstorm has the information to do this somewhere in its data structures, but I need guidance as to where.

What I’ve tried: I converted the data into 3D freesurfer volumes then inverting the tess-to-mri matrix (obtained from tess_interp_mri(tess_cortex_white_low_file, subjectimage_T1_mri_data)) in order to project from mri to tess, but this projected the data into the wrong location on the cortex, presumably because Brainstorm doesn’t use Freesurfer’s same orientation for volume files or for surface meshes.

In theory this should be easy—I’m assuming that Brainstorm keeps track of which vertices it keeps in the down-sampled cortices or what transformation it applies to the FreeSurfer surfaces, but I can’t find any information on it. Can this be done?

Thanks,
-Noah

Hi Noah,

I agree this sounds easy, but in practice it’s always complicated to convert anatomical information between different environments, mainly because each program uses a different coordinate system.

The way Brainstorm imports data from FreeSurfer is described here:
http://neuroimage.usc.edu/brainstorm/Tutorials/LabelFreeSurfer#Manual_import_of_the_anatomy
By doing these steps manually, you can import a new surface without having to reload the entire anatomy.
This can be automated with a script, as it is done in import_anatomy_fs.m

The surfaces are downsampled by Matlab’s reducepatch, the vertices that are kept are detected and used in this process, but not explicitly saved anywhere.

The import process should be easy to reproduce with your files, but I’m not sure about the export… I’ve never spent much time on export functions of anatomical data, as Brainstorm is not really meant to do any formal anatomical processing. In terms of MRI and surface management, what we offer is the minimum required for the purpose of MEG source imaging.
You will probably have to customize some of the functions (like out_tess_fs or out_tess_gii).

To work on personal copies of some functions, copy the original function to your $HOME/.brainstorm/process folder, as explained in this tutorial:
http://neuroimage.usc.edu/brainstorm/Tutorials/TutUserProcess

Does this help? Please let me know about which topic you need more specific help.

Cheers,
Francois

Thanks, Francois; this is very helpful! I will take a look at a these tutorials/functions and follow-up with more specific questions if I can’t get things to work.
One quick question: does Brainstorm save the affine transform anywhere that converts from FreeSurfer’s coordinate system (for, e.g., lh.white and rh.white surfaces) to the Brainstorm coordinate system? Or if not, where in the code is that transformation performed? Given the kinds of data we are importing and exporting, both directions should be trivial as long as that transform is not hard to reproduce.
Cheers,
-Noah

The transformation is not saved explicitly anywhere. It is done in two steps:

  1. Converting from “FreeSurfer RAS” to “Brainstorm MRI”:
    https://github.com/brainstorm-tools/brainstorm3/blob/master/toolbox/io/in_tess.m#L137
    http://neuroimage.usc.edu/brainstorm/CoordinateSystems#MRI_coordinates

  2. Converting from “Brainstorm MRI” to “Brainstorm SCS” (based on the three fiducials NAS/LPA/RPA defined in the MRI):
    https://github.com/brainstorm-tools/brainstorm3/blob/master/toolbox/io/in_tess.m#L208
    http://neuroimage.usc.edu/brainstorm/CoordinateSystems#Subject_Coordinate_System_.28SCS_.2F_CTF.29

Thanks, Francois!
Just to double-check: it looks like you linked the same source-code file and line for both steps; is that correct? Did you maybe intend line 208 in the second link?
Cheers,
-Noah

Absolutely, thanks for the correction