Mapping Electrode Locations to Average Brains

Tutorial Data:

You can download the data used in the tutorial below from here. These data consists of a FreeSurfer folder for PT001, PT002, and fsaverage. Place the PT001, PT002, and fsaverage folders in your FreeSurfer subjects directory and you should be able to run the commands below after you've run the localization tutorial commands.


1. Mapping cortical surface electrodes to the FreeSurfer average brain

To display group results of electrodes on the cortical surface, you can use FreeSurfer's surface based mapping of each individual brain to its average brain. The surface based mapping is derived by trying to align the gyrification patterns of the individual to that of the average and has been shown to be superior to volume-based mapping (i.e., warping the entire brain to that of an average brain) when doing fMRI group analyses (Fischl et al., 1999).


Slightly modified version of Figure 1 from Fischl et al. (1999), which illustrates how an individual brain is warped to a group average brain via gyrification patterns.


To use this Matlab code you first need to make sure you've downloaded the FreeSurfer average brain and placed it in your FreeSurfer subject folder along with all your patient folders. If you've already installed FreeSurfer on your computer, then you already have the FreeSurfer average brain and do not need to download it again. Then you collect the coordinates of each individual's brain relative to the average brain by doing something like this:



>>for a=1:length(subs),
>>    fprintf('Working on Participant %s\n',subs{a});
>>    [avgCoords, elecNames, isLeft]=sub2AvgBrain(subs{a},cfg);
>>    groupAvgCoords=[groupAvgCoords; avgCoords];
>>    groupLabels=[groupLabels; elecNames];
>>    groupIsLeft=[groupIsLeft; isLeft];


To run the above command, download the FreeSurfer folder's for PT001 and PT002 (below) and put them in your FreeSurfer subjects directory: 




Note that by default, sub2AvgBrain.m shows the electrode coordinates both on the individual's brain and the average brain so that you can check the accuracy of the mapping. For example, the plots for PT001 looks like this:



Then you plot all the electrodes on the average brain them using a plotElecPial.m:


>>cfg.elecCoord=[groupAvgCoords groupIsLeft];


>>cfg.title='PT001-2 on Avg. Brain';


To get the image below:


Finally, for depth electrodes (ignored in the above example) sub2AvgBrain.m maps them to MNI305 space via an affine transformation. These coordinates can also be visualized on the FreeSurfer average brain. For depth electrodes that lie in cortical grey matter, it would be better to use the surface based mapping. You can edit the subject's *.electrodeNames file to make this happen by labeling the cortical depth contacts as subdural electrodes (i.e., change the "D" in its row to an "S").


For more information on mapping to and from the MNI and FreeSurfer brains see this paper:


Accurate Nonlinear Mapping between MNI Volumetric and FreeSurfer Surface Coordinate Systems

Jianxiao Wu, Gia H Ngo, Douglas Greve, Jingwei Li, Tong He, Bruce Fischl, Simon B. Eickhoff, B.T. Thomas Yeo

bioRxiv 302794; doi:



**** GRATITUDE ****


Fischl, B., Sereno, M. I., Tootell, R. B. H., & Dale, A. M. (1999). High-resolution intersubject averaging and a coordinate system for the cortical surface. Human Brain Mapping, 8(4), 272–284.