07e45407e41f2662eb069523aa485b64a4e1bb84
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 15 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 searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

63)         coord = [x(iVoxel) y(iVoxel) z(iVoxel)];
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 15 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 added timer

Christoph Budziszewski authored 15 years ago

104)     tic
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

131) 
132) if ~isempty( fbsargs.timeline )
133) 	timeShiftIdx = fbsargs.timeline;
134) else 
135) 	timeShiftIdx = 1:nSamplePoints;
136) end
137) 
138)     for timeShiftIdx 
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

144) 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

146)             % get surrounding coordinate-IDs within radius
147)             sphere = fbs_buildSphere(mapping,iVoxel,radius,vdim);
148) 
149)             %build svm inputmatrix
150)             svmdata = [];
151)             svmlabel = [];
152)             anyvoxel = 1;
153)             for pstConditionGroup = 1:size(pst{1,anyvoxel},2)
154)                 for dp = 1:size(pst{1,anyvoxel}{1,pstConditionGroup},1) % data point
155)                     svmlabel = [svmlabel; lm_getSVMLabel(labelMap,eventList(pstConditionGroup,1))];
156)                     row = [];
157)                     for voxel = 1:size(sphere,2)
Christoph Budziszewski extracted psth-plot to extr...

Christoph Budziszewski authored 15 years ago

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

159)                     end
160)                     svmdata  = [svmdata; row];
161)                 end
162)             end
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

163) 
164)             if RANDOMIZE_DATAPOINTS
165)                 rndindex  = randperm(length(svmlabel));
166)                 svmdata   = svmdata(rndindex,:);
167)                 svmlabel  = svmlabel(rndindex);
168)             end
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

169)             
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

174)             x = coord(1);
175)             y = coord(2);
176)             z = coord(3);
Christoph Budziszewski fbs filename adaption, defa...

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

179)             
180)             display(sprintf('Status: %03u / %03u Timepoints, %05u / %05u Coordinates',timeShiftIdx,nSamplePoints,iVoxel,nVoxel));
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

181)         end  %for each voxel
182) 
Christoph Budziszewski FBS: status display

Christoph Budziszewski authored 15 years ago

183)         nii = make_nii(img3D,vdim,mask_image.hdr.hist.originator(1:3),16,...
184)             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

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

192) 
193)     %save memory!
194)     clear pst; 
195)     clear mask_image;
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

196) end
197) 
198) end