Skip to content

Data Handling (Matlab)

mario.senden edited this page Mar 2, 2021 · 11 revisions

Analyze-style data format (NIfTI)

It is recommended to use NIFTI tools for reading and writing NIfTI files.

Loading Data

Data can be loaded using the load_nii function. Below is an example on how to load a NIFTI file called prf_data.nii and extract functional data.

NIFTI = load_nii('prf_data.nii'); 
data = double(NIFTI.img);
data = permute(data, [4,1,2,4]);

Saving Results

Data can be saved using the save_nii function. Below is an example on how to save pRF mapping results to NIFTI files.

NIFTI.hdr.dime.dim(1) = 3; 
NIFTI.hdr.dime.dim(5) = 1;

mu_x_map = NIFTI;
mu_y_map = NIFTI;
sigma_map = NIFTI;
polar_angle_map = NIFTI;
eccentricity_map = NIFTI;

mu_x_map.img = results.mu_x;
mu_y_map.img = results.mu_y;
sigma_map.img = results.sigma;
polar_angle_map.img = results.polar_angle;
eccentricity_map.img = results.eccentricity;

save_nii(mu_x_map,'pRF_mu_x.nii');
save_nii(mu_y_map,'pRF_mu_y.nii');
save_nii(sigma_map,'pRF_sigma.nii');
save_nii(polar_angle_map,'pRF_polar_angle.nii');
save_nii(eccentricity_map,'pRF_eccentricity.nii');

BrainVoyager Data Format (VTC)

Handling BrainVoyager data in Matlab requires NeuroElf. Please refer to the official NeuroElf wiki for installation instructions.

Loading Data

BrainVoyager stores functional data in the space of a 3D anatomical data set in the VTC file format. For a detailed overview of the file format please refer to the corresponding entry in the official BrainVoyager User's guide.

This data can be loaded into Matab using NeuroElf's xff function.

Below is an example on how to load a VTC file called prf_data.vtc and extract functional data.

VTC = xff('prf_data.vtc');
data = VTC.VTCData;

Saving Results

Results can be saved to a native resolution volume map (NR-VMP) file. For a detailed overview of the file format please refer to the corresponding entry in the official BrainVoyager User's guide.

A new, empty, VMP file can be created using NeuroElf's BVQXfile function. Subsequently, the header information needs to be supplied such as the number of maps that need to be stored, how the dimensions of the maps relate to that of the corresponding anatomy (VMR file) etc. Finally, the maps need to be filed with results obtained from one (or several) of the CNI tools.

Below is an example on how to save pRF mapping results to a VMP file.

% create VMP fie
VMP = BVQXfile('new:vmp');

% provide general information
% some information can be taken from VTC files
VMP.NrOfMaps = 6;
VMP.XStart = VTC.XStart;
VMP.XEnd = VTC.XEnd;
VMP.YStart = VTC.YStart;
VMP.YEnd = VTC.YEnd;
VMP.ZStart = VTC.ZStart;
VMP.ZEnd = VTC.ZEnd;
VMP.Resolution = VTC.Resolution;

% provide map specific information (1st map)
VMP.Map(1).Type = 2;
VMP.Map(1).LowerThreshold = 0.2;
VMP.Map(1).UpperThreshold = 0.6;
VMP.Map(1).Name = 'R';
VMP.Map(1).RGBLowerThreshPos = [0 0 100];
VMP.Map(1).RGBUpperThreshPos = [0 0 255];
VMP.Map(1).ClusterSize = 4;
VMP.Map(1).DF1 = 302;
VMP.Map(1).ShowPositiveNegativeFlag = 1;
VMP.Map(1).UnknownValue = -1;

% provide map specific information (2nd map)
% some information can be taken from previous maps 
VMP.Map(2) = VMP.Map(1);           
VMP.Map(2).Type = 1;
VMP.Map(2).LowerThreshold = 0;
VMP.Map(2).UpperThreshold = 10;
VMP.Map(2).Name = 'Best-fit pRF: x, UseThreshMap: R';
VMP.Map(2).RGBLowerThreshPos = [0 100 0];
VMP.Map(2).RGBUpperThreshPos = [0 255 0];
VMP.Map(2).LUTName = '/hsv.olt';
VMP.Map(2).ClusterSize = 1;
VMP.Map(2).DF1 = 0;
VMP.Map(2).ShowPositiveNegativeFlag = 3;

% provide map specific information (3rd map)
% some information can be taken from previous maps 
VMP.Map(3) = VMP.Map(2);     
VMP.Map(3).Name = 'Best-fit pRF: y, UseThreshMap: R';
VMP.Map(3).RGBLowerThreshPos = [100 0 0];
VMP.Map(3).RGBUpperThreshPos = [255 0 0];

% provide map specific information (4th map)
% some information can be taken from previous maps
VMP.Map(4) = VMP.Map(2);      
VMP.Map(4).Name = 'Best-fit pRF: sigma, UseThreshMap: R';
VMP.Map(4).RGBLowerThreshPos = [100 0 100];
VMP.Map(4).RGBUpperThreshPos = [255 0 255];

% provide map specific information (5th map)
% some information can be taken from previous maps
VMP.Map(5) = VMP.Map(2);
VMP.Map(5).LowerThreshold = 0.001;
VMP.Map(5).Name = 'Eccentricity, UseThreshMap: R';
VMP.Map(5).RGBLowerThreshPos = [0 100 100];
VMP.Map(5).RGBUpperThreshPos = [0 255 255];
VMP.Map(5).LUTName = '/eccentricity_v1.olt';

% provide map specific information (6th map)
% some information can be taken from previous maps
VMP.Map(6) = VMP.Map(2); 
VMP.Map(6).LowerThreshold = 0.001;
VMP.Map(6).UpperThreshold = 3.1416;
VMP.Map(6).Name = 'Polar angle, UseThreshMap: R';
VMP.Map(6).RGBLowerThreshPos = [0 0 100];
VMP.Map(6).RGBUpperThreshPos = [0 0 255];
VMP.Map(6).LUTName = '/angle_v1.olt';

% assign results to maps
VMP.Map(1).VMPData = results.corr_fit;
VMP.Map(2).VMPData = results.mu_x;
VMP.Map(3).VMPData = results.mu_y;
VMP.Map(4).VMPData = results.sigma;
VMP.Map(5).VMPData = results.eccentricity;
VMP.Map(6).VMPData = results.polar_angle;

% save VMP
VMP.saveas('pRF_mapping.vmp')