b0a2dbf1076c250822bde906330ec8bace1d4896
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)     
112)     % tmp = spm_imatrix(V(kImage).mat); %
113)     % vdim = tmp(7:9); % Voxel-Size
Christoph Budziszewski fbs filename adaption, defa...

Christoph Budziszewski authored 15 years ago

114)     
115) 
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

119)     vdim = mask_image.hdr.dime.pixdim(2:4);
120)     if mask_image.hdr.dime.pixdim(1) == 1
121)         vdim = vdim .* [-1 1 1];
122)     end
123) 
124)     display(sprintf('starting timesliceing'));
125)     
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

126)     for timeShift = 1:timeLineEnd-timeLineStart+1
127)     % center timepoint && relative shift
128)     frameStart  = floor(-globalStart+1+timeShift - 0.5*decodeDuration);
129)     frameEnd    = min(ceil(frameStart+decodeDuration + 0.5*decodeDuration),-globalStart+globalEnd);
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

132) 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

134)             % get surrounding coordinate-IDs within radius
135)             sphere = fbs_buildSphere(mapping,iVoxel,radius,vdim);
136) 
137)             %build svm inputmatrix
138)             svmdata = [];
139)             svmlabel = [];
140)             anyvoxel = 1;
141)             for pstConditionGroup = 1:size(pst{1,anyvoxel},2)
142)                 for dp = 1:size(pst{1,anyvoxel}{1,pstConditionGroup},1) % data point
143)                     svmlabel = [svmlabel; lm_getSVMLabel(labelMap,eventList(pstConditionGroup,1))];
144)                     row = [];
145)                     for voxel = 1:size(sphere,2)
146)                         row = [row, pst{1,voxel}{1,pstConditionGroup}(dp,frameStart:frameEnd)]; % label,[value,value,...],[value,value,...]...
147)                     end
148)                     svmdata  = [svmdata; row];
149)                 end
150)             end
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

151) 
152)             if RANDOMIZE_DATAPOINTS
153)                 rndindex  = randperm(length(svmlabel));
154)                 svmdata   = svmdata(rndindex,:);
155)                 svmlabel  = svmlabel(rndindex);
156)             end
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

157)             
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

162)             x = coord(1);
163)             y = coord(2);
164)             z = coord(3);
Christoph Budziszewski fbs filename adaption, defa...

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

167) 
168)         end  %for each voxel
169) 
Christoph Budziszewski fbs filename adaption, defa...

Christoph Budziszewski authored 15 years ago

170)         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));
171)         save_nii(nii,fullfile(savePath,sprintf('%s-%03g',subjects{s}.name,timeShift)));
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

183) end
184) 
185) end