ba8f816897804516fcc5ec8a468b90a2134cdcfd
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 snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

26) RANDOMIZE_DATAPOINTS = header.svmrnd;
27) svmopts = fbsargs.svmopts;
28) 
Christoph Budziszewski nifti save functional, but...

Christoph Budziszewski authored 15 years ago

29) 
30) 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

31) disp(sprintf('batch processing  %g subjects.',nSubjects));
32) 
33) for s = 1:nSubjects
Christoph Budziszewski nifti save functional, but...

Christoph Budziszewski authored 15 years ago

34) 
35) 
36)     
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

37)     elapsed = struct; %measure the timing
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

42)     tic;
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

43)     volumes = spm_vol(getImageFileList(subjects{s}.dir,sessionlist,args.mask));
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

44)     elapsed.loadList = toc;
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

46)     tic 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

47)     [extr x y z] = calculateRoiImageData(volumes,subjects{s}.roiFile);
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

48)     elapsed.calcExtr = toc;
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

50) % clear volumes; %save memory ??
51) % disp('cleared volumes');
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

52) tic
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

66)     end
67)     
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

68)     mapping.indexToCoordMap = indexToCoordMap;
69)     mapping.coordToIndexMap = coordToIndexMap;
70) 
71)     elapsed.mapping = toc;
72)     
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

73)     % calculate psth
74)     
75)     warn = warning('off','all');
76)     pstopts.des = subjects{s}.des;
77) 
78)     disp(sprintf('computing psth for %g voxel.',nVoxel));
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

79) tic 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

80) 
81)     for iVoxel = 1:nVoxel
82)         rawdata = [];
83)         for iImage = 1:length(extr);
84)             tmp = extr(iImage);
85)             rawdata = [rawdata tmp.dat(iVoxel)];
86)         end
87) %         coordNameHelper = strcat('v',num2str(iVoxel));
88)         pst{iVoxel} = calculatePST(args.timeline,pstopts,rawdata); % do not store in subjectStruct, so we can clear it later.
89) 
90)          p = iVoxel/nVoxel*100;
91)          if(mod(iVoxel,nVoxel/100)==0)
92)              sprintf(' %g%%\t complete',p);
93)          end
94)     end
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

95) elapsed.psth = toc;
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

96)     disp('psth done');
97)     warning(warn);
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

99)     %run searchlight
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

100) tic
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

101)     
102)     display(sprintf('rastering %g coordinates with approx. %g mm radius',nVoxel,radius));
103)     % for each timeslice
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

104)     globalStart = timeline.psthStart;
105)     globalEnd = timeline.psthEnd;
106)     decodeDuration = timeline.decodeDuration;
107)     labelMap = timePointArgs.labelMap;
108)     eventList = pstopts.eventList;
109)     
110)     % tmp = spm_imatrix(V(kImage).mat); %
111)     % vdim = tmp(7:9); % Voxel-Size
112)     vdim = [3,3,3.5];
113)     
Christoph Budziszewski nifti save functional, but...

Christoph Budziszewski authored 15 years ago

114)     mask_image = load_nii(subjects{s}.roiFile.fname);
115)     
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

121)         img3D = zeros(size(mask_image)); %output image
122) 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

124)             % get surrounding coordinate-IDs within radius
125)             sphere = fbs_buildSphere(mapping,iVoxel,radius,vdim);
126) 
127)             %build svm inputmatrix
128)             svmdata = [];
129)             svmlabel = [];
130)             anyvoxel = 1;
131)             for pstConditionGroup = 1:size(pst{1,anyvoxel},2)
132)                 for dp = 1:size(pst{1,anyvoxel}{1,pstConditionGroup},1) % data point
133)                     svmlabel = [svmlabel; lm_getSVMLabel(labelMap,eventList(pstConditionGroup,1))];
134)                     row = [];
135)                     for voxel = 1:size(sphere,2)
136)                         row = [row, pst{1,voxel}{1,pstConditionGroup}(dp,frameStart:frameEnd)]; % label,[value,value,...],[value,value,...]...
137)                     end
138)                     svmdata  = [svmdata; row];
139)                 end
140)             end
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

141) 
142)             if RANDOMIZE_DATAPOINTS
143)                 rndindex  = randperm(length(svmlabel));
144)                 svmdata   = svmdata(rndindex,:);
145)                 svmlabel  = svmlabel(rndindex);
146)             end
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

147)             
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

152)             x = coord(1);
153)             y = coord(2);
154)             z = coord(3);
155)             img3D(x,y,z) = decode/100; %damn percentage
156) %             mask_image.img(x,y,z) = decode/100;
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

157) 
158)         end  %for each voxel
159) 
Christoph Budziszewski nifti save functional, but...

Christoph Budziszewski authored 15 years ago

160)         nii = make_nii(img3D,vdim,mask_image.hdr.hist.originator(1:3),16,'decode performance'); %default origin
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

161)         save_nii(nii,sprintf('TESTFILE%g',timeShift));
Christoph Budziszewski nifti save functional, but...

Christoph Budziszewski authored 15 years ago

162) %         save_nii(mask_image,sprintf('MTESTFILE%g',timeShift));
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

165)     display('rastering done');
166) elapsed.decode = toc;
167) 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

168) 
169)     clear pst; %save memory!
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

170) assignin('base','timing',elapsed);
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

171) end
172) 
173) end