12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- % Preprocess.m
- %
- % This funciton preprocesses data of the studyforrest data set. It searches in
- % the provided directory for the anatomy and ses-movie/func directories.
- %
- % input:
- % dir - directory of the subject to preprocess (if empty processes the current directory)
- % runId - the run index to process (varies from 1 to 8)
- function Preprocess(dir, runId)
-
- if (~isempty(dir) && ~strcmp(dir(end),'/'))
- dir = [dir '/'];
- end
- curDir = '';
- if (~strcmp(dir(1),'/'))
- curDir = pwd;
- curDir = [curDir '/'];
- end
- numOfVolumes = 451;
-
- anatomyScan = [curDir dir 'anatomy/highres001.nii,1'];
- scansDir = [curDir dir 'ses-movie/func/'];
- regex = [num2str(runId) '_bold.nii'];
- scans = spm_select('ExtFPList', scansDir, regex, 1:numOfVolumes);
- assert(size(scans,1) <= numOfVolumes, 'Detected more files than asked. Check if file is already preprocessed.');
- if (size(scans,1) == 0)
- warning(['Could not find any scans for directory ' dir ' and run ID ' num2str(runId)]);
- return;
- end
- % Realign - Estimate and Write (mean)
- matlabbatch{1}.spm.spatial.realign.estwrite.data{1} = cellstr(scans);
- %%
- matlabbatch{1}.spm.spatial.realign.estwrite.eoptions.quality = 0.9;
- matlabbatch{1}.spm.spatial.realign.estwrite.eoptions.sep = 4;
- matlabbatch{1}.spm.spatial.realign.estwrite.eoptions.fwhm = 5;
- matlabbatch{1}.spm.spatial.realign.estwrite.eoptions.rtm = 1;
- matlabbatch{1}.spm.spatial.realign.estwrite.eoptions.interp = 2;
- matlabbatch{1}.spm.spatial.realign.estwrite.eoptions.wrap = [0 0 0];
- matlabbatch{1}.spm.spatial.realign.estwrite.eoptions.weight = '';
- matlabbatch{1}.spm.spatial.realign.estwrite.roptions.which = [0 1];
- matlabbatch{1}.spm.spatial.realign.estwrite.roptions.interp = 4;
- matlabbatch{1}.spm.spatial.realign.estwrite.roptions.wrap = [0 0 0];
- matlabbatch{1}.spm.spatial.realign.estwrite.roptions.mask = 1;
- matlabbatch{1}.spm.spatial.realign.estwrite.roptions.prefix = 'r';
- % Coregister - Estimate
- matlabbatch{2}.spm.spatial.coreg.estimate.ref = cellstr(anatomyScan);
- matlabbatch{2}.spm.spatial.coreg.estimate.source(1) = cfg_dep('Realign: Estimate & Reslice: Mean Image', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','rmean'));
- matlabbatch{2}.spm.spatial.coreg.estimate.other(1) = cfg_dep('Realign: Estimate & Reslice: Realigned Images (Sess 1)', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','sess', '()',{1}, '.','cfiles'));
- matlabbatch{2}.spm.spatial.coreg.estimate.eoptions.cost_fun = 'nmi';
- matlabbatch{2}.spm.spatial.coreg.estimate.eoptions.sep = [4 2];
- matlabbatch{2}.spm.spatial.coreg.estimate.eoptions.tol = [0.02 0.02 0.02 0.001 0.001 0.001 0.01 0.01 0.01 0.001 0.001 0.001];
- matlabbatch{2}.spm.spatial.coreg.estimate.eoptions.fwhm = [7 7];
- % Normalize - Estimate and write
- matlabbatch{3}.spm.spatial.normalise.estwrite.subj.vol = cellstr(anatomyScan);
- matlabbatch{3}.spm.spatial.normalise.estwrite.subj.resample(1) = cfg_dep('Coregister: Estimate: Coregistered Images', substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','cfiles'));
- matlabbatch{3}.spm.spatial.normalise.estwrite.eoptions.biasreg = 0.0001;
- matlabbatch{3}.spm.spatial.normalise.estwrite.eoptions.biasfwhm = 60;
- matlabbatch{3}.spm.spatial.normalise.estwrite.eoptions.tpm = {'/home/ga58sux/workspace/spm/spm12/tpm/TPM.nii'};
- matlabbatch{3}.spm.spatial.normalise.estwrite.eoptions.affreg = 'mni';
- matlabbatch{3}.spm.spatial.normalise.estwrite.eoptions.reg = [0 0.001 0.5 0.05 0.2];
- matlabbatch{3}.spm.spatial.normalise.estwrite.eoptions.fwhm = 0;
- matlabbatch{3}.spm.spatial.normalise.estwrite.eoptions.samp = 3;
- matlabbatch{3}.spm.spatial.normalise.estwrite.woptions.bb = [-78 -112 -70
- 78 76 85];
- matlabbatch{3}.spm.spatial.normalise.estwrite.woptions.vox = [3 3 3];
- matlabbatch{3}.spm.spatial.normalise.estwrite.woptions.interp = 4;
- matlabbatch{3}.spm.spatial.normalise.estwrite.woptions.prefix = 'w';
- matlabbatch{4}.spm.spatial.smooth.data(1) = cfg_dep('Normalise: Estimate & Write: Normalised Images (Subj 1)', substruct('.','val', '{}',{3}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{1}, '.','files'));
- % Smooth data
- matlabbatch{4}.spm.spatial.smooth.fwhm = [8 8 8];
- matlabbatch{4}.spm.spatial.smooth.dtype = 0;
- matlabbatch{4}.spm.spatial.smooth.im = 0;
- matlabbatch{4}.spm.spatial.smooth.prefix = 's';
- % run created matlab batch
- spm_jobman('run', matlabbatch);
- end
|