Export Surface Images as the GIfTI File Format using MATLAB

From BESA® Wiki
Jump to: navigation, search
Module information
Modules BESA Research Standard or higher
Version BESA Research 6.1 or higher

GIfTI (Geometry format under the Neuroimaging Informatics Technology Initiative) is a file format for surface-based neuroimaging data and many surface-based brain mapping applications support to read this file format.

Although BESA Research does not have a feature to export surface image results (cortical LORETA, cortical CLARA, and minimum norm) in the GIfTI file format directly, surface image results exported from BESA Research to MATLAB can be exported in the GIfTI file format (*.gii) using BESA MATLAB Readers and GIfTI library for MATLAB.

ExportToGIfTI 01.png

Procedure

  1. Export surface image results to MATLAB using the Send to MATLAB dialog in the Source Analysis window of BESA Research (File → Send to MATLAB...).
    • Select the "3D image", "Current image", and "Voxel amplitude" options in the Send to MATLAB dialog if the options are not selected.
  2. After finishing the data exporting process, type desktop in the MATLAB window to open the MATLAB desktop window.
    • In the besa_image data structure, exported surface image results can be found.
  3. Export surface image results in GIfTI file format: refer to the MATLAB script shown below.
    • It is required to download the BESA MATLAB Readers and GIfTI library for MATLAB if you do not have these toolboxes yet.
    • Please modify the example script below to add the BESA MATLAB Readers and GIfTI library for MATLAB folders to the search path for MATLAB and to set the file path of the sfh file used in BESA Research.


% Export surface image values to GIfTI (.gii)
 
% -------------------------------------------------------------------------
% Add paths: BESA2MATLAB (BESA MATLAB Readers) and GIfTI library for MATLAB
% -------------------------------------------------------------------------
 
%addpath('xxx'); % add BESA2MATLAB
%addpath('xxx'); % add GIfTI library for MATLAB
 
% -------------------------------------------------------------------------
% Set the file path of the sfh file used in BESA Research
% -------------------------------------------------------------------------
 
%fileSfh = 'xxx\xxx.sfh';
 
% -------------------------------------------------------------------------
% Prepare white matter surface
% -------------------------------------------------------------------------
 
% Read BESA coregistration information from a .sfh file
sfh = readBESAsfh(fileSfh);
 
% Read a reduced white matter surface (in Talairach space)
%   ex: xxx\MRIFiles\SurfaceFiles\MRISeg_MRI_T1_TAL_WM_RED.srf
BrainSurfaceReduced = [sfh.Talairach.TalBrainSurfacePath(1:end-4) '_RED.srf'];
wm = readBESAsrf(BrainSurfaceReduced);
% Read an original white matter surface (in Talairach space) if you want to use it.
%wm = readBESAsrf(sfh.Talairach.TalBrainSurfacePath);
 
 
% NOTE: The wm.CoordsVertices is in the BrainVoyager coordinate system.
val_shift = 128;
surface          = [];
surface.faces    = wm.Triangles + 1; % In MATLAB, an index starts from 1.
surface.vertices = ...
    [ wm.CoordsVertices(:,3) - val_shift, ...
    -(wm.CoordsVertices(:,1) - val_shift),...
    -(wm.CoordsVertices(:,2) - val_shift)];
% Flip x axis
surface.vertices(:,1) = -surface.vertices(:,1);
 
% -------------------------------------------------------------------------
% Interpolate the surface image values
% -------------------------------------------------------------------------
 
value = griddata(...
    besa_image.xcoordinates, besa_image.ycoordinates, besa_image.zcoordinates, ...
    besa_image.data,...
    surface.vertices(:,1), surface.vertices(:,2), surface.vertices(:,3), 'nearest');
 
value(isnan(value)) = 0;
 
% -------------------------------------------------------------------------
% Prepare GIfTI objects
% -------------------------------------------------------------------------
 
% White matter surface
gSurface = gifti(surface);
 
% Intepolated surface image values
gSurfaceImage = [];
gSurfaceImage.cdata = value;
gSurfaceImage = gifti(gSurfaceImage);
 
% Plot the white matter surface
%figure; plot(gSurface);
% Plot the white matter surface with surface image values
%figure; plot(gSurface, gSurfaceImage);
 
% -------------------------------------------------------------------------
% Save as the GIfTI file format (*.gii)
% -------------------------------------------------------------------------
 
save(gSurface, 'surface.gii', 'Base64Binary');
save(gSurfaceImage, 'surfaceImage.gii', 'Base64Binary');

See also