eXTReMe Tracker
Dec 012010
 

Script to preprocess 4D fMRI time series:

spm_defaults;
 global defaults;
%% Slice Timing
display('Step 1: Slice Timing');
sliceorder = [1:2:17 2:2:16];
 refslice = 17;
 TR = 1;
 precision = 5;
 nslices = length(sliceorder);
P = dir('4Dout*.nii');
 P = char(P.name);
 TA = TR - TR/nslices;
if precision > 0
 TAstr = num2str(TA, precision);
 TA = str2double(TAstr);
 end
timing(1) = TA / (nslices -1);
 timing(2) = TR - TA;
 spm_slice_timing(P, sliceorder, refslice, timing);
%% Realignment and Reslicing
display('Step 2: Realignment');
 P=dir('a4Dout*.nii');
 P=char(P.name);
 FlagsC = struct('quality',1,'fwhm',5,'rtm',1,'interp',1);   %Flags for realignment
 spm_realign(P,FlagsC);
display('Step 3: Reslice');
 %Flags for reslicing
 FlagsR = struct('mask', 1, 'mean', 1,'interp',4,'which',0, 'wrap', defaults.realign.write.wrap);
 spm_reslice(P,FlagsR);
 display('... saving motion parameters as a motion_report.pdf ');
 saveas(gcf, 'motion_report', 'pdf');
 close all;
%% Normalization
display('Step 4: Normalization');
template = fullfile(spm('Dir'),'templates', 'EPI.nii');
 srcimage = 'mean*.nii';
meanimg = dir(srcimage);
 P = char(meanimg.name);
 snmat_name = strrep(P, '.nii', '_sn.mat');
 if exist(snmat_name, 'file')
 disp(['... removing existing file named: ' snmat_name]);
 delete(snmat_name);
 end
 objmask_name = '';
spm_normalise(template, P, snmat_name, defaults.normalise.estimate.weight, objmask_name,defaults.normalise.estimate);
%% Write Normalized Images
display('Step 5: Writing Normalized Images');
PP = dir('a4D*.nii');
 PP = char(PP.name);
 spm_write_sn(PP, snmat_name, defaults.normalise.write);
%% Smoothing
display('Step 6: Smoothing ... ');
PP = dir('wa4D*.nii');
 PP = char(PP.name);
 PP = cellstr(PP);
for list = 1:length(PP)
 Q = strcat('s', PP{list});
 spm_smooth(PP{list}, Q, defaults.smooth.fwhm);
 end
 %display(sprintf('\nPreprocessing compled.\n\nTime taken %d sec.\n', x));
Getting data extracted from time series:
Create ROI maps with WFU Pickatlas and MarsBar.
 Extract the contents of masks by:
 XYZ=struct(roi); XYZ=XYZ.XYZ;
%% Convert XYZ to mm
XYZ=[XYZ; ones(1, size(XYZ,2))]; XYZmm=roi.mat*XYZ; XYZmm(end,:)=[];XYZmm=XYZmm';
%%
p=spm_vol('swaf00xx.nii');
 [time_data]=spm_get_data(p, XYZ);
 time_data=mean(time_data,2);