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?
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 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).
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
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