5c481dda2a46829fb76340a34e881f9b868e9024
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 fbs timeline mod

Christoph Budziszewski authored 14 years ago

29) 
30) 
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

34) 
35) 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

40) 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

45)     tic;
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

50)     tic 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

53)     
Christoph Budziszewski added timer

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

57)     
58)     nVoxel = size(extr(1).dat,1);
59) 
60)     indexToCoordMap = java.util.HashMap;
61)     coordToIndexMap = java.util.HashMap;
62)     for iVoxel = 1:nVoxel
Christoph Budziszewski debugging

Christoph Budziszewski authored 14 years ago

63)         coord = [x(iVoxel) y(iVoxel) z(iVoxel)]
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

64)         a = java.util.Vector(3,0);
65)         a.add(0,coord(1));
66)         a.add(1,coord(2));
67)         a.add(2,coord(3));
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

70)     end
71)     
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

72)     mapping.indexToCoordMap = indexToCoordMap;
73)     mapping.coordToIndexMap = coordToIndexMap;
74) 
Christoph Budziszewski added timer

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

76)     
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

83)     tic
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 14 years ago

94) %          p = iVoxel/nVoxel*100;
95) %          if(mod(iVoxel,floor(nVoxel/100))==0)
96) %              sprintf(' %g%%\t complete',p);
97) %          end
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

98)     end
Christoph Budziszewski added timer

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

100)     disp('psth done');
101)     warning(warn);
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

103)     %run searchlight
Christoph Budziszewski fbs custom timeline mod, fo...

Christoph Budziszewski authored 14 years ago

104)     pause(0.001) % flush system event queue (respond to ctrl-c)
Christoph Budziszewski added timer

Christoph Budziszewski authored 15 years ago

105)     tic
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

109)     globalStart     = timeline.psthStart;
110)     globalEnd       = timeline.psthEnd;
111)     decodeDuration  = timeline.decodeDuration;
112)     labelMap        = timePointArgs.labelMap;
113)     eventList       = pstopts.eventList;
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

115)     res             = timeline.tr*timeline.trFactor;
116)     
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

119)     
120) 
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

131)     nSamplePoints = ((timeLineEnd-timeLineStart)/res) +1;
Christoph Budziszewski fbs timeline mod

Christoph Budziszewski authored 14 years ago

132) 
Christoph Budziszewski fbs custom timeline mod, fo...

Christoph Budziszewski authored 14 years ago

133) if isempty( fbsargs.timeline )
Christoph Budziszewski debugging

Christoph Budziszewski authored 14 years ago

134) 	fbsTimeLine = 1:nSamplePoints;
135)     fbsTimeLine = fbsTimeLine +globalStart;
Christoph Budziszewski fbs timeline mod

Christoph Budziszewski authored 14 years ago

136) else 
Christoph Budziszewski debugging

Christoph Budziszewski authored 14 years ago

137) 	fbsTimeLine = fbsargs.timeline;
Christoph Budziszewski fbs timeline mod

Christoph Budziszewski authored 14 years ago

138) end
139) 
Christoph Budziszewski fbs custom timeline mod, fo...

Christoph Budziszewski authored 14 years ago

140) 
141)     for timeShiftIdx = fbsTimeLine
142)         
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

148) 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

149)         for iVoxel = 1:nVoxel % linear structure avoids 3D-Loop.
Christoph Budziszewski fbs custom timeline mod, fo...

Christoph Budziszewski authored 14 years ago

150)             if (mod(iVoxel,100)== 0)
Christoph Budziszewski better eye candy

Christoph Budziszewski authored 14 years ago

151)                 display(sprintf('Status: %03u / %03u Timepoints, %05u / %05u Coordinates',find(fbsTimeLine == timeShiftIdx),length(fbsTimeLine),iVoxel,nVoxel));
Christoph Budziszewski fbs custom timeline mod, fo...

Christoph Budziszewski authored 14 years ago

152)                 pause(0.001) %flush system event queue
153)             end
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

154)             % get surrounding coordinate-IDs within radius
155)             sphere = fbs_buildSphere(mapping,iVoxel,radius,vdim);
Christoph Budziszewski debugging

Christoph Budziszewski authored 14 years ago

156) %             pause
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

157) 
158)             %build svm inputmatrix
159)             svmdata = [];
160)             svmlabel = [];
161)             anyvoxel = 1;
162)             for pstConditionGroup = 1:size(pst{1,anyvoxel},2)
163)                 for dp = 1:size(pst{1,anyvoxel}{1,pstConditionGroup},1) % data point
164)                     svmlabel = [svmlabel; lm_getSVMLabel(labelMap,eventList(pstConditionGroup,1))];
165)                     row = [];
166)                     for voxel = 1:size(sphere,2)
Christoph Budziszewski extracted psth-plot to extr...

Christoph Budziszewski authored 15 years ago

167)                         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

168)                     end
169)                     svmdata  = [svmdata; row];
170)                 end
171)             end
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

172) 
173)             if RANDOMIZE_DATAPOINTS
Christoph Budziszewski debugging

Christoph Budziszewski authored 14 years ago

174) %                 [svmlabel svmdata]
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

175)                 rndindex  = randperm(length(svmlabel));
176)                 svmdata   = svmdata(rndindex,:);
177)                 svmlabel  = svmlabel(rndindex);
178)             end
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

179)             
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

182) 
Christoph Budziszewski debugging

Christoph Budziszewski authored 14 years ago

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

Christoph Budziszewski authored 15 years ago

184)             x = coord(1);
185)             y = coord(2);
186)             z = coord(3);
Christoph Budziszewski fbs filename adaption, defa...

Christoph Budziszewski authored 15 years ago

187)             
188)             img3D(x,y,z) = ((decode/100)-0.5)*2; % range [-1:1]
Christoph Budziszewski FBS: status display

Christoph Budziszewski authored 14 years ago

189)             
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

190)         end  %for each voxel
191) 
Christoph Budziszewski FBS: status display

Christoph Budziszewski authored 14 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

201) 
202)     %save memory!
203)     clear pst; 
204)     clear mask_image;
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

205) end
206) 
207) end