Matlab scripting examples
We will list useful scripts / command-line calls that are shipped within Lead-DBS on this site. Please note that a lot of these scripts are buggy and may not be well maintained. Also, the documentation may be outdated. But they provide some insight about useful tools for expert users.
3D Visualization / Elvis viewer
ea_mnifigure
This snippet will open the 3D viewer "Elvis" of Lead-DBS with an atlas. It is a normal MATLAB figure, so you can then plot additional content onto it.
ea_keepatlaslabels
This call will hide all atlas structures from an open viewer that are not specified in the script.
ea_setplanes
This call will move or hide (when supplying NaN) the MRI planes to specific mm values.
ea_view
Store the current 3D view (v = ea_view;) as variable v or set the current 3D view to the view stored in v.
Elvis scripting example scripts
Export / Data Visualization
ea_surfice
Overlay a nifti file to the MNI space surfice templates and export results as png.
Coordinates and image manipulation
Querying electrode placement
Electrode coordinates are stored inside the ea_reconstruction.mat
files inside patient folders and also in the M.elstruct
variable of the Lead_groupanalysis.mat
files of Lead group projects.
will deliver the right-hemispheric ({1}
) x (laterality), y (anterio-posterior axis) and z (dorso-ventral / superior-inferior axis) coordinates in template space. Usually (by default) these will be within ICBM 152 2009b Nonlinear Asymmetric space, the most modern and precise "MNI space". See here for more about different spaces. Left hemispheric electrodes will be stored in the second cell ({2}
). To get coordinates in native subject space, use the reco.native.coords_mm
(before brain shift correction, i.e. inside the postoperative volume) or the reco.scrf.coords_mm
entry (after brain shift correction, i.e. inside the anchor modality. Note that those are not ACPC coordinates.
By default, ACPC coordinates are not computed, but this can be done. To enable it, change the line prefs.reco.saveACPC=0;
to prefs.reco.saveACPC=1;
within the preferences file (to open the preferences file hit cmd+P in the Lead-DBS main GUI.
Once this flag is enabled, the reco
variable will have another entry called acpc
with the same logic.
If you are dealing with more than two electrodes, the reco.space.
cells will have more than two entries but usually, right hemispheric electrodes should be stored in the first and left in the second entry.
Inside these entries, contacts are numbered from bottom to top, for instance
will deliver the left hemispheric ({2}
) third most ventral ((3,:)
) contact inside the native space anchor modality (which is usually the T1 image). Of note, those are usually not that useful and not comparable across subjects. The mni
or acpc
coordinates are and we strongly suggest using mni
coordinates for comparisons or statistical analyses.
Querying active electrode contacts from a Lead group project file
It can be convenient to query coordinates of active contacts directly using Lead group projects. For instance, the below code snippet would denote all active contacts of a project after loading the dataset-*.mat
file inside the leadgroup
derivatives folder.
As in the example above, the entries in the right hemisphere will be in {1}, the ones in the left in the {2} cell. In this example, if multiple electrode contacts were active, their coordinates would get averaged (mean()
command). This could be key to note in case of segmented electrodes, since it could lead to unwanted effects if e.g. segments a and b (but not c) are active. As always, plotting the results to make sure they check out makes sense.
ea_spherical_roi
This function will make a spherical region of interest around a user identified mni coordinates. It takes file name, mni coordinates in (mm), radius (in mm), and path of space template file in which the sphere will be identified, as arguments
ea_vox2mm
Converts voxel-coordinates to mm-coordinates. Coordinates need to be row vector: N*3
ea_flip_lr_nonlinear
Flip files / coords nonlinearly from Left to Right hemisphere (or vice versa) based on asymmetric template
Last updated