spatial and temporal grouping functionality
Christoph Budziszewski

Christoph Budziszewski commited on 2009-08-03 16:18:15
Zeige 10 geänderte Dateien mit 45 Einfügungen und 58 Löschungen.


git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@202 83ab2cfd-5345-466c-8aeb-2b2739fb922d
... ...
@@ -11,15 +11,6 @@ timeline.decodeDuration  = header.frameShift.decodeDuration;
11 11
 timeLineStart  = timeline.frameShiftStart;
12 12
 timeLineEnd    = timeline.frameShiftEnd;
13 13
 
14
-% for iVoxel = 1:nVoxel
15
-%     rawdata = [];
16
-%     for iImage = 1:length(extr);
17
-%         tmp = extr(iImage);
18
-%         rawdata = [rawdata tmp.dat(iVoxel)];
19
-%     end
20
-%     pst{iVoxel} = calculatePST(timeline,calculatePstOpts,rawdata);
21
-% end
22
-
23 14
 timePointArgs.pst           = subjectStruct.pst;
24 15
 timePointArgs.labelMap      = LabelMap(header.classDef.labelCells,header.classDef.conditionCells);
25 16
 timePointArgs.eventList     = header.classDef.eventMatrix;
... ...
@@ -30,6 +21,7 @@ decodePerformance = [];
30 21
 for index = 1:timeLineEnd-timeLineStart+1
31 22
 
32 23
     svmdata      = timePointMatrix{index}(:,2:size(timePointMatrix{index},2));
24
+    svmdata      = header.timeframeGroupingfunction(svmdata);
33 25
     svmlabel     = timePointMatrix{index}(:,1);
34 26
 
35 27
     if RANDOMIZE_DATAPOINTS
... ...
@@ -1,13 +1,13 @@
1
-function [extr voxelcount] = calculateImageData(filenameList, coordlist)
1
+function [extr voxelcount] = calculateImageData(filenameList, coordlist,gFkt)
2 2
 
3
+%center coordinates
3 4
 vox = [];
4
-% radius = [];
5 5
 nCoords = size(coordlist,1);
6 6
 for iCoord = 1:nCoords
7 7
    vox = [vox ; coordlist(iCoord).coord];
8
-%    radius = [radius , coordlist(iCoord).rad];
9 8
 end
10 9
 
10
+%maximum extracted voxels over all images
11 11
 voxelcount = 0;
12 12
 
13 13
 V = filenameList;
... ...
@@ -15,14 +15,13 @@ nImage = numel(V);
15 15
 nVoxel = nCoords;
16 16
 for kImage=1:nImage
17 17
     roicenter = round(inv(V(kImage).mat)*[vox, ones(nVoxel,1)]');
18
-%     x = roicenter(1,:);
19
-%     y = roicenter(2,:);
20
-%     z = roicenter(3,:);
21 18
 
22 19
     subvoxelcount = 0;
23 20
     for iVoxel = 1:nVoxel
24 21
 
22
+        %radius
25 23
         rad = coordlist(iVoxel).rad;
24
+
26 25
         tmp = spm_imatrix(V(kImage).mat);
27 26
         vdim = tmp(7:9);
28 27
         vxrad = ceil((rad*ones(nVoxel,3))./(ones(nVoxel,1)*vdim))';
... ...
@@ -45,12 +44,16 @@ for kImage=1:nImage
45 44
 
46 45
         dat = spm_sample_vol(V(kImage), x, y, z,0);
47 46
  
47
+        %%Implement Spatial grouping here
48
+        
49
+        dat = gFkt(dat);
50
+        
51
+        % no grouping
48 52
         for iSubVoxel = 1:size(dat,1)
49 53
             subvoxelcount = subvoxelcount +1;
50 54
             extr(kImage).dat(subvoxelcount)    = dat(iSubVoxel);
51 55
         end
52
-%         extr(kImage).mean(iVoxel)     = nanmean(dat);
53
-%         extr(kImage).nvx(iVoxel)      = numel(dat);
56
+        
54 57
     end
55 58
     voxelcount = max(voxelcount,subvoxelcount);
56 59
 end   
... ...
@@ -1,35 +1,15 @@
1 1
 function defineGlobals()
2
-global SVMCROSSVAL_SPMDIR;
2
+
3 3
 global SVMCROSSVAL_TOOLBOXPATH;
4
-SVMCROSSVAL_TOOLBOXPATH = fullfile(SVMCROSSVAL_SPMDIR,'toolbox','SVMCrossVal');
4
+SVMCROSSVAL_TOOLBOXPATH = fullfile(getSpmPath,'toolbox','SVMCrossVal');
5 5
 
6 6
 global SVMCROSSVAL_STUDYDIR;
7 7
 SVMCROSSVAL_STUDYDIR = fullfile(SVMCROSSVAL_TOOLBOXPATH,'study');
8 8
 
9
-%define global constants
10
-global SVMCROSSVAL_USE_DRIVE_CHECK_HACK;
11
-%enables subroutine to check if image path starts with 'D'
12
-SVMCROSSVAL_USE_DRIVE_CHECK_HACK                  = 1;  
13
-
14
-global SVMCROSSVAL_CROSSVAL_METHOD_DEF;
15
-% supported classification methods
16
-SVMCROSSVAL_CROSSVAL_METHOD_DEF.svmcrossval       = 'svm crossval';
17
-SVMCROSSVAL_CROSSVAL_METHOD_DEF.classPerformance  = 'svm class performance';
18
-SVMCROSSVAL_CROSSVAL_METHOD_DEF.crossSubject      = 'svm across subject testing';
19
-SVMCROSSVAL_CROSSVAL_METHOD_DEF.somTraining       = 'som Training';
20
-
21
-global SVMCROSSVAL_VOXEL_SELECTION_MODE_DEF;
22
-% supported voxel selection methods
23
-SVMCROSSVAL_VOXEL_SELECTION_MODE_DEF.manualGui    = 'manually defined in GUI';
24
-SVMCROSSVAL_VOXEL_SELECTION_MODE_DEF.roiImage     = 'use ROI image by pop-up image selector';
25
-
26 9
 global SVMCROSSVAL_SUBJECT_PREFIX;
27
-% internally used to prefix subject-ids starting with numbers.
28 10
 SVMCROSSVAL_SUBJECT_PREFIX                        = 'subject';
29 11
 
30 12
 global SVMCROSSVAL_SUBJECTSTRUCT_NAME;
31 13
 SVMCROSSVAL_SUBJECTSTRUCT_NAME                    = 'subjectStruct';
32 14
 
33
-global SVMCROSSVAL_PREPROCESSED_DATA_NAME;
34
-SVMCROSSVAL_PREPROCESSED_DATA_NAME                = 'preprocessedData';
35 15
 end
36 16
\ No newline at end of file
... ...
@@ -0,0 +1,5 @@
1
+function fkt = getSpatialGroupingFunction(model)
2
+fields = get(model.selRoiGrouping,'UserData');
3
+value = get(model.selRoiGrouping,'Value');
4
+fkt = fields{value};
5
+end
... ...
@@ -0,0 +1,5 @@
1
+function fkt = getTemporalGroupingFunction(model)
2
+fields = get(model.selTimeframeGrouping,'UserData');
3
+value = get(model.selTimeframeGrouping,'Value');
4
+fkt = fields{value};
5
+end
... ...
@@ -31,7 +31,7 @@ psthOpts.psthNorm      = getPsthNormalizationMethod(model);
31 31
 
32 32
 switch task
33 33
     case 'COORD'
34
-        disp('COORD');
34
+        disp('LUT Approach');
35 35
        
36 36
         out = struct;
37 37
         out.header = struct;
... ...
@@ -48,11 +48,12 @@ switch task
48 48
         coordargs.coords        = parseCoordinateTextField(model);
49 49
         coordargs.mask          = mask;
50 50
         coordargs.psthOpts      = psthOpts;
51
+        coordargs.groupingFkt   = getSpatialGroupingFunction(model);
51 52
         
52 53
         out.subjectdata = runCoordTable(coordargs);
53 54
 
54 55
     case 'ROI'
55
-        disp('ROI');
56
+        disp('ROI Image Approach');
56 57
         out = struct;
57 58
         out.header = struct;
58 59
         out.header.type = 'ROI';
... ...
@@ -117,6 +118,7 @@ end
117 118
 warn = warning('off','all');
118 119
 header            = preprocessedData.header;
119 120
 header.frameShift = getFrameShiftParams(model);
121
+header.timeframeGroupingfunction = getTemporalGroupingFunction(model);
120 122
 data              = preprocessedData.subjectdata;
121 123
 
122 124
 switch task
... ...
@@ -1,7 +1,5 @@
1 1
 function subjectData = runCoordTable(args)
2 2
 
3
-% global SVMCROSSVAL_SUBJECTSTRUCT_NAME;
4
-
5 3
     disp('run coord table')
6 4
     
7 5
     subjects = args.subjects;
... ...
@@ -12,20 +10,21 @@ function subjectData = runCoordTable(args)
12 10
     disp(sprintf('batch processing %g subjects.',nSubjects));
13 11
 
14 12
     for s = 1:nSubjects
13
+        % load SPM Design 
15 14
         subjectStruct{s}.dir = fullfile(args.basedir,cell2mat(subjects(s)));
16 15
         d = load(fullfile(subjectStruct{s}.dir,'results','SPM.mat'));
17 16
         subjectStruct{s}.des = d.SPM;
18 17
         subjectStruct{s}.name = cell2mat(subjects(s));
19
-        
18
+        % load ROI look-up table
20 19
         map = load(fullfile(subjectStruct{s}.dir,'results','roi','coord_map.mat'));
21 20
         subjectStruct{s}.coords = getSubjectCoordinates(args.coords,map);
22 21
         
23
-%         nVoxel = size(subjectStruct{s}.coords,1);
24
-        
22
+        %preload images
25 23
         disp('fetching volume definitions, please wait');
26 24
         subjectStruct{s}.volumes = spm_vol(getImageFileList(subjectStruct{s}.dir,sessionlist,args.mask));
27 25
       
28
-        [extr nExtractedVoxel] = calculateImageData(subjectStruct{s}.volumes,subjectStruct{s}.coords);
26
+        %extract voxel values
27
+        [extr nExtractedVoxel] = calculateImageData(subjectStruct{s}.volumes,subjectStruct{s}.coords,args.groupingFkt);
29 28
          
30 29
         pstopts.des = subjectStruct{s}.des;
31 30
         pstopts.eventList = args.eventList;
... ...
@@ -1,7 +1,5 @@
1 1
 function subjectStruct  = runROIImageMaskMode(args)
2 2
 
3
-% global SVMCROSSVAL_SUBJECTSTRUCT_NAME;
4
-
5 3
 subjects = args.subjects;
6 4
    
7 5
 nSubjects = numel(subjects);
... ...
@@ -5,7 +5,7 @@ function ui_main(varargin)
5 5
     frameHeight=450;
6 6
     
7 7
     frame = figure('Visible','off','Position',[0,0,frameWidth,frameHeight]);
8
-    movegui(frame,'west'); % get this thing visible on smaller displays.
8
+    movegui(frame,'center'); % get this thing visible on smaller displays.
9 9
     set(frame,'Name','SVMCrossVal Decode Performance 4 SPM');
10 10
     set(frame,'NumberTitle','off');
11 11
     set(frame,'MenuBar','none');
... ...
@@ -92,7 +92,8 @@ end
92 92
 %%%%% ui elements
93 93
 function model = createFirstStepPanel(model,parent)
94 94
     norm1Model = {'none','mean','minmax'};
95
-    roiGroupMethods = {'none','mean','max','median'};
95
+    roiGroupMethodNames = {'none','mean','max','median'};
96
+    roiGroupMethodFunctions = {@(in)in, @(in)nanmean(in),@(in)nanmax(in),@(in)nanmedian(in)};
96 97
 
97 98
     main_grid = cell(2,4);
98 99
     main_grid{1,1} = [0 0.7 0.4 0.3];
... ...
@@ -243,11 +244,10 @@ function model = createFirstStepPanel(model,parent)
243 244
          model.selRoiGrouping = uicontrol(pOptions,'Style','popupmenu',...
244 245
                 'Units','normalized',...
245 246
                 'Position',cell2mat(optGrid(2,4)),...
246
-                'String',roiGroupMethods,...
247
-                'UserData',roiGroupMethods);
247
+                'String',roiGroupMethodNames,...
248
+                'UserData',roiGroupMethodFunctions);
248 249
          set(model.selRoiGrouping,'BackgroundColor','w');
249 250
         
250
-        
251 251
         % COORD TABLE
252 252
         pVoxel = uipanel(parent,'Title','ROI','Position',cell2mat(main_grid(1,3)));
253 253
         set(pVoxel,'BackgroundColor','w');
... ...
@@ -281,6 +281,9 @@ end
281 281
 function model = createSecondStepPanel(model,parent)
282 282
 basecolor = 'w';
283 283
 
284
+TimeframeGroupingStrings = {'none','mean'};%,'sum,'max','median'};
285
+TimeframeGroupingFunctions = {@(in)in,@(in)nanmean(in,2)};%,'sum',','max','median'};
286
+
284 287
 pTime = uipanel(parent,'Units','normalized','Position',[0.0 0.7 1 0.3]);
285 288
     set(pTime,'Title','Decode Timeframe Options');
286 289
     set(pTime,'BackgroundColor',basecolor);
... ...
@@ -310,14 +313,14 @@ pTime = uipanel(parent,'Units','normalized','Position',[0.0 0.7 1 0.3]);
310 313
     model.txtFrameShiftEnd     = createTextField(pTime,cell2mat(time_grid(3,2)),'');
311 314
     model.txtFrameShiftDur     = createTextField(pTime,cell2mat(time_grid(2,3)),'');
312 315
     
313
-    TimeframeGroupingOptions = {'none','sum','mean','max','median'};
316
+
314 317
     
315 318
     model.selTimeframeGrouping = uicontrol(pTime,'Style','popupmenu',...
316 319
         'Units','normalized',...
317 320
         'Position',cell2mat(time_grid(2,4)),...
318
-        'String',TimeframeGroupingOptions,...
319
-        'UserData',TimeframeGroupingOptions);
320
-    set(model.selTimeframeGrouping,'Enable','off');
321
+        'String',TimeframeGroupingStrings,...
322
+        'UserData',TimeframeGroupingFunctions);
323
+    set(model.selTimeframeGrouping,'Enable','on');
321 324
     
322 325
 pSVM = uipanel(parent,'Units','normalized','Position',[0 0.3 0.5 0.4]);
323 326
     set(pSVM,'Title','SVM Classification');