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

Christoph Budziszewski authored 15 years ago

29) disp(sprintf('batch processing  %g subjects.',nSubjects));
30) 
31) for s = 1:nSubjects
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

33)     disp(sprintf('processing subject %s.',subjects{s}.name));
34)     % load image data
35)    
36)     disp('fetching volume definitions, please wait');
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

37)     tic;
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

41)     tic 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

44)     
45) clear volumes; %save memory ??
46) disp('cleared volumes');
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

47) tic
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

48)     
49)     nVoxel = size(extr(1).dat,1);
50) 
51)     indexToCoordMap = java.util.HashMap;
52)     coordToIndexMap = java.util.HashMap;
53)     for iVoxel = 1:nVoxel
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

54)         coord = [x(iVoxel) y(iVoxel) z(iVoxel)];
55)         a = java.util.Vector(3,0);
56)         a.add(0,coord(1));
57)         a.add(1,coord(2));
58)         a.add(2,coord(3));
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

61)     end
62)     
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

63)     mapping.indexToCoordMap = indexToCoordMap;
64)     mapping.coordToIndexMap = coordToIndexMap;
65) 
66)     elapsed.mapping = toc;
67)     
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

68)     % calculate psth
69)     
70)     warn = warning('off','all');
71)     pstopts.des = subjects{s}.des;
72) 
73)     disp(sprintf('computing psth for %g voxel.',nVoxel));
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

74) tic 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

91)     disp('psth done');
92)     warning(warn);
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

95) tic
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

99)     globalStart = timeline.psthStart;
100)     globalEnd = timeline.psthEnd;
101)     decodeDuration = timeline.decodeDuration;
102)     labelMap = timePointArgs.labelMap;
103)     eventList = pstopts.eventList;
104)     
105)     img3D = [];
106)     % tmp = spm_imatrix(V(kImage).mat); %
107)     % vdim = tmp(7:9); % Voxel-Size
108)     vdim = [3,3,3.5];
109)     
110)     for timeShift = 1:timeLineEnd-timeLineStart+1
111)     % center timepoint && relative shift
112)     frameStart  = floor(-globalStart+1+timeShift - 0.5*decodeDuration);
113)     frameEnd    = min(ceil(frameStart+decodeDuration + 0.5*decodeDuration),-globalStart+globalEnd);
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

133) 
134)             if RANDOMIZE_DATAPOINTS
135)                 rndindex  = randperm(length(svmlabel));
136)                 svmdata   = svmdata(rndindex,:);
137)                 svmlabel  = svmlabel(rndindex);
138)             end
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

139)             
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

142) 
143)             coord= mapping.indexToCoordMap.get(iVoxel);
144)             img3D(coord',timeShift) = decode;
145) 
146)         end  %for each voxel
147) 
148)         nii = make_nii(img3D,vdim,[],16,'decode'); %default origin
149)         save_nii(nii,sprintf('TESTFILE%g',timeShift));
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

152)     display('rastering done');
153) elapsed.decode = toc;
154) 
Christoph Budziszewski snapshot, working on fbs

Christoph Budziszewski authored 15 years ago

155) 
156)     clear pst; %save memory!
Christoph Budziszewski searchlight ready. missing...

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

158) end
159) 
160) end