Export Surface Images as the GIfTI File Format using MATLAB

From BESA® Wiki
Revision as of 15:27, 25 May 2021 by Jaehyun (Talk | contribs)

(diff) ← Older revision | Approved revision (diff) | Latest revision (diff) | Newer revision → (diff)
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 doesn't have a feature to export surface image results (cortical LORETA, cortical CLARA, and minimum norm) as the GIfTI file format directly, exported surface image results from BESA Research to MATLAB can be exported as the GIfTI file format (*.gii) using BESA MATLAB Readers and GIfTI library for MATLAB.

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 as the GIfTI file format, refer to the MATLAB script below.
    • It is needed to download the BESA MATLAB Readers and GIfTI library for MATLAB if you don't have the 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