function output = runFBSImageMaskMode(header,subjectdata,fbsargs) args = header.args; subjects = subjectdata; nSubjects = numel(subjects); sessionlist = args.sessionList; pstopts = args.psthOpts; pstopts.eventList = args.eventList; pstopts.sessionList = sessionlist; radius = fbsargs.radius; timeline = header.timeline; timeline.frameShiftStart = header.frameShift.frameShiftStart; timeline.frameShiftEnd = header.frameShift.frameShiftEnd; timeline.decodeDuration = header.frameShift.decodeDuration; timePointArgs.labelMap = LabelMap(header.classDef.labelCells,header.classDef.conditionCells); timePointArgs.eventList = header.classDef.eventMatrix; timeLineStart = timeline.frameShiftStart; timeLineEnd = timeline.frameShiftEnd; disp(sprintf('batch processing %g subjects.',nSubjects)); for s = 1:nSubjects disp(sprintf('processing subject %s.',subjects{s}.name)); % load image data disp('fetching volume definitions, please wait'); volumes = spm_vol(getImageFileList(subjects{s}.dir,sessionlist,args.mask)); disp('computing volume values, please wait'); [extr x y z] = calculateRoiImageData(volumes,subjects{s}.roiFile); clear volumes; %save memory ?? disp('cleared volumes'); nVoxel = size(extr(1).dat,1); indexToCoordMap = java.util.HashMap; coordToIndexMap = java.util.HashMap; for iVoxel = 1:nVoxel coord = [x(iVoxel),y(iVoxel),z(iVoxel)]; indexToCoordMap.put(iVoxel,coord); coordToIndexMap.put(coord,iVoxel); end subjects{s}.indexToCoordMap = indexToCoordMap; subjects{s}.coordToIndexMap = coordToIndexMap; % calculate psth warn = warning('off','all'); pstopts.des = subjects{s}.des; disp(sprintf('computing psth for %g voxel.',nVoxel)); for iVoxel = 1:nVoxel rawdata = []; for iImage = 1:length(extr); tmp = extr(iImage); rawdata = [rawdata tmp.dat(iVoxel)]; end % coordNameHelper = strcat('v',num2str(iVoxel)); pst{iVoxel} = calculatePST(args.timeline,pstopts,rawdata); % do not store in subjectStruct, so we can clear it later. p = iVoxel/nVoxel*100; if(mod(iVoxel,nVoxel/100)==0) sprintf(' %g%%\t complete',p); end end disp('psth done'); warning(warn); %run searchlight display(sprintf('rastering %g coordinates with approx. %g mm radius',nVoxel,radius)); % for each timeslice for index = 1:timeLineEnd-timeLineStart+1 timeShift = index; % center timepoint && relative shift frameStart = floor(-globalStart+1+timeShift - 0.5*decodeDuration); frameEnd = min(ceil(frameStart+decodeDuration + 0.5*decodeDuration),-globalStart+globalEnd); for iVoxel = 1:nVoxel % linear structure avoids 3D-Loop. % get coordinate for iVoxel % coord = % get surrounding coordinates within radius % sphere = % calculate decode performance on these coordinates svmdata = timePointMatrix{index}(:,2:size(timePointMatrix{index},2)); svmlabel = timePointMatrix{index}(:,1); if RANDOMIZE_DATAPOINTS rndindex = randperm(length(svmlabel)); svmdata = svmdata(rndindex,:); svmlabel = svmlabel(rndindex); end decode = svm_single_crossval(svmlabel,svmdata,svmopts); % save the decode value to the corresponding coordinate end display('rastering done'); % save data for timeslice end %for each timeslice clear pst; %save memory! end end