a37f1788af995389637ce633dad36feca794b698
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

1) function output =  runFBSImageMaskMode(header,subjectdata,fbsargs)
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

2) addpath('NIFTI_20090325');
3) 
Christoph Budziszewski manual renamings, better FB...

Christoph Budziszewski authored 15 years ago

4) savePath = fullfile('output',datestr(now,30));
Christoph Budziszewski fbs filename adaption, defa...

Christoph Budziszewski authored 15 years ago

5) mkdir(savePath);
6) 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

7) args = header.args;
8) 
9) subjects = subjectdata;
10) nSubjects = numel(subjects);
11) sessionlist = args.sessionList;
12) pstopts = args.psthOpts;
13) pstopts.eventList = args.eventList;
14) pstopts.sessionList = sessionlist;
15) 
16) radius = fbsargs.radius;
17) 
18) timeline = header.timeline;
19) timeline.frameShiftStart = header.frameShift.frameShiftStart;
20) timeline.frameShiftEnd   = header.frameShift.frameShiftEnd;
21) timeline.decodeDuration  = header.frameShift.decodeDuration;
22) 
23) timePointArgs.labelMap      = LabelMap(header.classDef.labelCells,header.classDef.conditionCells);
24) timePointArgs.eventList     = header.classDef.eventMatrix;
25) 
26) timeLineStart  = timeline.frameShiftStart;
27) timeLineEnd    = timeline.frameShiftEnd;
28) 
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

29) RANDOMIZE_DATAPOINTS = header.svmrnd;
30) svmopts = fbsargs.svmopts;
31) 
Christoph Budziszewski nifti save functional, but...

Christoph Budziszewski authored 15 years ago

32) 
33) 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

34) disp(sprintf('batch processing  %g subjects.',nSubjects));
35) 
36) for s = 1:nSubjects
Christoph Budziszewski added timer

Christoph Budziszewski authored 15 years ago

37)     elapsed{s} = struct; %measure the timing
Christoph Budziszewski nifti save functional, but...

Christoph Budziszewski authored 15 years ago

38) 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

39)     disp(sprintf('processing subject %s.',subjects{s}.name));
40)     % load image data
41)    
42)     disp('fetching volume definitions, please wait');
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

43)     tic;
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

44)     volumes = spm_vol(getImageFileList(subjects{s}.dir,sessionlist,args.mask));
Christoph Budziszewski added timer

Christoph Budziszewski authored 15 years ago

45)     elapsed{s}.loadList = toc;
46)     
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

47)     disp('computing volume values, please wait');
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

48)     tic 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

49)     [extr x y z] = calculateRoiImageData(volumes,subjects{s}.roiFile);
Christoph Budziszewski added timer

Christoph Budziszewski authored 15 years ago

50)     elapsed{s}.calcExtr = toc;
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

51)     
Christoph Budziszewski added timer

Christoph Budziszewski authored 15 years ago

52)     clear volumes; %save memory ??
53)     disp('cleared volumes');
54)     tic
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

55)     
56)     nVoxel = size(extr(1).dat,1);
57) 
58)     indexToCoordMap = java.util.HashMap;
59)     coordToIndexMap = java.util.HashMap;
60)     for iVoxel = 1:nVoxel
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

61)         coord = [x(iVoxel) y(iVoxel) z(iVoxel)];
62)         a = java.util.Vector(3,0);
63)         a.add(0,coord(1));
64)         a.add(1,coord(2));
65)         a.add(2,coord(3));
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

66)         indexToCoordMap.put(iVoxel,coord);
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

67)         coordToIndexMap.put(a,iVoxel);
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

68)     end
69)     
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

70)     mapping.indexToCoordMap = indexToCoordMap;
71)     mapping.coordToIndexMap = coordToIndexMap;
72) 
Christoph Budziszewski added timer

Christoph Budziszewski authored 15 years ago

73)     elapsed{s}.mapping = toc;
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

74)     
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

75)     % calculate psth
76)     
77)     warn = warning('off','all');
78)     pstopts.des = subjects{s}.des;
79) 
80)     disp(sprintf('computing psth for %g voxel.',nVoxel));
Christoph Budziszewski added timer

Christoph Budziszewski authored 15 years ago

81)     tic
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

82) 
83)     for iVoxel = 1:nVoxel
84)         rawdata = [];
85)         for iImage = 1:length(extr);
86)             tmp = extr(iImage);
87)             rawdata = [rawdata tmp.dat(iVoxel)];
88)         end
89) %         coordNameHelper = strcat('v',num2str(iVoxel));
90)         pst{iVoxel} = calculatePST(args.timeline,pstopts,rawdata); % do not store in subjectStruct, so we can clear it later.
91) 
92)          p = iVoxel/nVoxel*100;
Christoph Budziszewski added timer

Christoph Budziszewski authored 15 years ago

93)          if(mod(iVoxel,floor(nVoxel/100))==0)
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

94)              sprintf(' %g%%\t complete',p);
95)          end
96)     end
Christoph Budziszewski added timer

Christoph Budziszewski authored 15 years ago

97)     elapsed{s}.psth = toc;
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

98)     disp('psth done');
99)     warning(warn);
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

100)     clear extr;
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

101)     %run searchlight
Christoph Budziszewski added timer

Christoph Budziszewski authored 15 years ago

102)     tic
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

103)     
104)     display(sprintf('rastering %g coordinates with approx. %g mm radius',nVoxel,radius));
105)     % for each timeslice
Christoph Budziszewski added timer

Christoph Budziszewski authored 15 years ago

106)     globalStart     = timeline.psthStart;
107)     globalEnd       = timeline.psthEnd;
108)     decodeDuration  = timeline.decodeDuration;
109)     labelMap        = timePointArgs.labelMap;
110)     eventList       = pstopts.eventList;
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

111)     
Christoph Budziszewski extracted psth-plot to extr...

Christoph Budziszewski authored 15 years ago

112)     res             = timeline.tr*timeline.trFactor;
113)     
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

114)     % tmp = spm_imatrix(V(kImage).mat); %
115)     % vdim = tmp(7:9); % Voxel-Size
Christoph Budziszewski fbs filename adaption, defa...

Christoph Budziszewski authored 15 years ago

116)     
117) 
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

118)     
Christoph Budziszewski nifti save functional, but...

Christoph Budziszewski authored 15 years ago

119)     mask_image = load_nii(subjects{s}.roiFile.fname);
120)     
Christoph Budziszewski fbs filename adaption, defa...

Christoph Budziszewski authored 15 years ago

121)     vdim = mask_image.hdr.dime.pixdim(2:4);
122)     if mask_image.hdr.dime.pixdim(1) == 1
123)         vdim = vdim .* [-1 1 1];
124)     end
125) 
126)     display(sprintf('starting timesliceing'));
127)     
Christoph Budziszewski extracted psth-plot to extr...

Christoph Budziszewski authored 15 years ago

128)     nSamplePoints = ((timeLineEnd-timeLineStart)/res) +1;
129)     for timeShiftIdx = 1:nSamplePoints
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

130)     % center timepoint && relative shift
Christoph Budziszewski extracted psth-plot to extr...

Christoph Budziszewski authored 15 years ago

131)     frameStartIdx  = floor(-globalStart+1+timeShiftIdx - 0.5*decodeDuration);
Christoph Budziszewski added some batch files, wor...

Christoph Budziszewski authored 15 years ago

132)     frameEndIdx    = min(ceil(frameStartIdx+decodeDuration + 0.5*decodeDuration),-globalStart+globalEnd);
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

133) 
Christoph Budziszewski fbs filename adaption, defa...

Christoph Budziszewski authored 15 years ago

134)         img3D = zeros(size(mask_image)); %output image prepare
Christoph Budziszewski nifti save functional, but...

Christoph Budziszewski authored 15 years ago

135) 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

136)         for iVoxel = 1:nVoxel % linear structure avoids 3D-Loop.
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

137)             % get surrounding coordinate-IDs within radius
138)             sphere = fbs_buildSphere(mapping,iVoxel,radius,vdim);
139) 
140)             %build svm inputmatrix
141)             svmdata = [];
142)             svmlabel = [];
143)             anyvoxel = 1;
144)             for pstConditionGroup = 1:size(pst{1,anyvoxel},2)
145)                 for dp = 1:size(pst{1,anyvoxel}{1,pstConditionGroup},1) % data point
146)                     svmlabel = [svmlabel; lm_getSVMLabel(labelMap,eventList(pstConditionGroup,1))];
147)                     row = [];
148)                     for voxel = 1:size(sphere,2)
Christoph Budziszewski extracted psth-plot to extr...

Christoph Budziszewski authored 15 years ago

149)                         row = [row, pst{1,voxel}{1,pstConditionGroup}(dp,frameStartIdx:frameEndIdx)]; % label,[value,value,...],[value,value,...]...
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

150)                     end
151)                     svmdata  = [svmdata; row];
152)                 end
153)             end
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

154) 
155)             if RANDOMIZE_DATAPOINTS
156)                 rndindex  = randperm(length(svmlabel));
157)                 svmdata   = svmdata(rndindex,:);
158)                 svmlabel  = svmlabel(rndindex);
159)             end
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

160)             
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

161)             decode = svm_single_crossval(svmlabel,svmdata,svmopts);
162)             % save the decode value to the corresponding coordinate
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

163) 
164)             coord= mapping.indexToCoordMap.get(iVoxel);
Christoph Budziszewski nifti save functional, but...

Christoph Budziszewski authored 15 years ago

165)             x = coord(1);
166)             y = coord(2);
167)             z = coord(3);
Christoph Budziszewski fbs filename adaption, defa...

Christoph Budziszewski authored 15 years ago

168)             
169)             img3D(x,y,z) = ((decode/100)-0.5)*2; % range [-1:1]
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

170)         end  %for each voxel
171) 
Christoph Budziszewski fbs filename adaption, defa...

Christoph Budziszewski authored 15 years ago

172)         nii = make_nii(img3D,vdim,mask_image.hdr.hist.originator(1:3),16,sprintf('decode performance, time relative to onset: %g to %g sec',frameStart,frameEnd));
Christoph Budziszewski extracted psth-plot to extr...

Christoph Budziszewski authored 15 years ago

173)         save_nii(nii,fullfile(savePath,sprintf('%s-%03g',subjects{s}.name,timeShiftIdx)));
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

174)     end %for each timeslice
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

175)     display('rastering done');
Christoph Budziszewski manual renamings, better FB...

Christoph Budziszewski authored 15 years ago

176)     display(sprintf('result images saved to %s',savePath));
177)     
Christoph Budziszewski fbs filename adaption, defa...

Christoph Budziszewski authored 15 years ago

178)     elapsed{s}.decode = toc;
Christoph Budziszewski added timer

Christoph Budziszewski authored 15 years ago

179)     assignin('base','timing',elapsed);
Christoph Budziszewski fbs filename adaption, defa...

Christoph Budziszewski authored 15 years ago

180) 
181)     %save memory!
182)     clear pst; 
183)     clear mask_image;
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

184) end
185) 
186) end