Browse code

spatial and temporal grouping functionality

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@202 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on03/08/2009 16:18:15
Showing1 changed files
... ...
@@ -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))';
... ...
@@ -44,13 +43,17 @@ for kImage=1:nImage
44 43
         end;
45 44
 
46 45
         dat = spm_sample_vol(V(kImage), x, y, z,0);
46
+ 
47
+        %%Implement Spatial grouping here
48
+        
49
+        dat = gFkt(dat);
47 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   
Browse code

refined gui elements

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@191 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on03/05/2009 04:08:13
Showing1 changed files
... ...
@@ -40,7 +40,7 @@ for kImage=1:nImage
40 40
             x = roicenter(1,iVoxel)+x(sel(:));
41 41
             y = roicenter(2,iVoxel)+y(sel(:));
42 42
             z = roicenter(3,iVoxel)+z(sel(:));
43
-            [x y z]
43
+%             [x y z]
44 44
         end;
45 45
 
46 46
         dat = spm_sample_vol(V(kImage), x, y, z,0);
Browse code

debugging

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@185 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on26/04/2009 18:27:56
Showing1 changed files
... ...
@@ -40,6 +40,7 @@ for kImage=1:nImage
40 40
             x = roicenter(1,iVoxel)+x(sel(:));
41 41
             y = roicenter(2,iVoxel)+y(sel(:));
42 42
             z = roicenter(3,iVoxel)+z(sel(:));
43
+            [x y z]
43 44
         end;
44 45
 
45 46
         dat = spm_sample_vol(V(kImage), x, y, z,0);
Browse code

radius frontend enabled, fixed backend problems. radius working

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@162 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on18/03/2009 14:50:47
Showing1 changed files
... ...
@@ -1,27 +1,32 @@
1
-function [extr voxelcount] = calculateImageData(filenameList, voxelList, rad)
1
+function [extr voxelcount] = calculateImageData(filenameList, coordlist)
2
+
3
+vox = [];
4
+% radius = [];
5
+nCoords = size(coordlist,1);
6
+for iCoord = 1:nCoords
7
+   vox = [vox ; coordlist(iCoord).coord];
8
+%    radius = [radius , coordlist(iCoord).rad];
9
+end
10
+
2 11
 voxelcount = 0;
3 12
 
4 13
 V = filenameList;
5
-
6
-vox = voxelList;
7
-nVoxel = size(vox,1);
8 14
 nImage = numel(V);
9
-
10
-% rad = 0;
11
-
15
+nVoxel = nCoords;
12 16
 for kImage=1:nImage
13 17
     roicenter = round(inv(V(kImage).mat)*[vox, ones(nVoxel,1)]');
14
-    x = roicenter(1,:);
15
-    y = roicenter(2,:);
16
-    z = roicenter(3,:);
17
-
18
-    tmp = spm_imatrix(V(kImage).mat);
19
-    vdim = tmp(7:9);
20
-    vxrad = ceil((rad*ones(nVoxel,3))./(ones(nVoxel,1)*vdim))';
18
+%     x = roicenter(1,:);
19
+%     y = roicenter(2,:);
20
+%     z = roicenter(3,:);
21 21
 
22 22
     subvoxelcount = 0;
23 23
     for iVoxel = 1:nVoxel
24 24
 
25
+        rad = coordlist(iVoxel).rad;
26
+        tmp = spm_imatrix(V(kImage).mat);
27
+        vdim = tmp(7:9);
28
+        vxrad = ceil((rad*ones(nVoxel,3))./(ones(nVoxel,1)*vdim))';
29
+        
25 30
         if rad==0
26 31
             x = roicenter(1,iVoxel);
27 32
             y = roicenter(2,iVoxel);
Browse code

radius backend working

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@161 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on18/03/2009 13:53:10
Showing1 changed files
... ...
@@ -1,4 +1,5 @@
1
-function extr = calculateImageData(filenameList, voxelList, rad)
1
+function [extr voxelcount] = calculateImageData(filenameList, voxelList, rad)
2
+voxelcount = 0;
2 3
 
3 4
 V = filenameList;
4 5
 
... ...
@@ -14,10 +15,11 @@ for kImage=1:nImage
14 15
     y = roicenter(2,:);
15 16
     z = roicenter(3,:);
16 17
 
17
-            tmp = spm_imatrix(V(kImage).mat);
18
-            vdim = tmp(7:9);
19
-            vxrad = ceil((rad*ones(nVoxel,3))./(ones(nVoxel,1)*vdim))';
18
+    tmp = spm_imatrix(V(kImage).mat);
19
+    vdim = tmp(7:9);
20
+    vxrad = ceil((rad*ones(nVoxel,3))./(ones(nVoxel,1)*vdim))';
20 21
 
22
+    subvoxelcount = 0;
21 23
     for iVoxel = 1:nVoxel
22 24
 
23 25
         if rad==0
... ...
@@ -35,13 +37,16 @@ for kImage=1:nImage
35 37
             z = roicenter(3,iVoxel)+z(sel(:));
36 38
         end;
37 39
 
38
-
39 40
         dat = spm_sample_vol(V(kImage), x, y, z,0);
40 41
         
41
-        extr(kImage).dat(iVoxel,:)    = dat;
42
-        extr(kImage).mean(iVoxel)     = nanmean(dat);
43
-        extr(kImage).nvx(iVoxel)      = numel(dat);
44
-    end;
42
+        for iSubVoxel = 1:size(dat,1)
43
+            subvoxelcount = subvoxelcount +1;
44
+            extr(kImage).dat(subvoxelcount)    = dat(iSubVoxel);
45
+        end
46
+%         extr(kImage).mean(iVoxel)     = nanmean(dat);
47
+%         extr(kImage).nvx(iVoxel)      = numel(dat);
48
+    end
49
+    voxelcount = max(voxelcount,subvoxelcount);
50
+end   
45 51
 
46
-end;
47 52
 end
48 53
\ No newline at end of file
Browse code

radius bug fast behoben.

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@160 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on17/03/2009 14:50:47
Showing1 changed files
... ...
@@ -14,6 +14,9 @@ for kImage=1:nImage
14 14
     y = roicenter(2,:);
15 15
     z = roicenter(3,:);
16 16
 
17
+            tmp = spm_imatrix(V(kImage).mat);
18
+            vdim = tmp(7:9);
19
+            vxrad = ceil((rad*ones(nVoxel,3))./(ones(nVoxel,1)*vdim))';
17 20
 
18 21
     for iVoxel = 1:nVoxel
19 22
 
... ...
@@ -22,9 +25,6 @@ for kImage=1:nImage
22 25
             y = roicenter(2,iVoxel);
23 26
             z = roicenter(3,iVoxel);
24 27
         else
25
-            tmp = spm_imatrix(V(kImage).mat);
26
-            vdim = tmp(7:9);
27
-            vxrad = ceil((rad*ones(1,3))./(ones(nVoxel,1)*vdim))';
28 28
             [x y z] = ndgrid(-vxrad(1,iVoxel):sign(vdim(1)):vxrad(1,iVoxel), ...
29 29
                 -vxrad(2,iVoxel):sign(vdim(2)):vxrad(2,iVoxel), ...
30 30
                 -vxrad(3,iVoxel):sign(vdim(3)):vxrad(3,iVoxel));
... ...
@@ -37,7 +37,8 @@ for kImage=1:nImage
37 37
 
38 38
 
39 39
         dat = spm_sample_vol(V(kImage), x, y, z,0);
40
-        extr(kImage).dat(iVoxel)      = dat;
40
+        
41
+        extr(kImage).dat(iVoxel,:)    = dat;
41 42
         extr(kImage).mean(iVoxel)     = nanmean(dat);
42 43
         extr(kImage).nvx(iVoxel)      = numel(dat);
43 44
     end;
Browse code

enabled radius. but does not work with r>0 !

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@156 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on16/03/2009 18:55:40
Showing1 changed files
... ...
@@ -1,4 +1,4 @@
1
-function extr = calculateImageData(filenameList, voxelList)
1
+function extr = calculateImageData(filenameList, voxelList, rad)
2 2
 
3 3
 V = filenameList;
4 4
 
... ...
@@ -6,7 +6,7 @@ vox = voxelList;
6 6
 nVoxel = size(vox,1);
7 7
 nImage = numel(V);
8 8
 
9
-rad = 0;
9
+% rad = 0;
10 10
 
11 11
 for kImage=1:nImage
12 12
     roicenter = round(inv(V(kImage).mat)*[vox, ones(nVoxel,1)]');
Browse code

schwimmen.

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@139 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on25/02/2009 16:53:36
Showing1 changed files
... ...
@@ -6,6 +6,8 @@ vox = voxelList;
6 6
 nVoxel = size(vox,1);
7 7
 nImage = numel(V);
8 8
 
9
+rad = 0;
10
+
9 11
 for kImage=1:nImage
10 12
     roicenter = round(inv(V(kImage).mat)*[vox, ones(nVoxel,1)]');
11 13
     x = roicenter(1,:);
Browse code

coordTabel works for JZ006

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@138 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on25/02/2009 15:49:55
Showing1 changed files
... ...
@@ -1,36 +1,4 @@
1
-% filenameList as in SPM.xY.VY
2
-% voxelList in [x y z], 1 coordinate per row
3
-
4 1
 function extr = calculateImageData(filenameList, voxelList)
5
-TRANSFORM_METHOD = 'single';
6
-%function extr = calculateImageData(voxelList,des,smoothed)
7
-% global USE_DRIVE_CHECK_HACK;
8
-
9
-% dtype='PSTH';
10
-
11
-% switch dtype 
12
-%     case 'PSTH'
13
-%         V=des.xY.VY;
14
-%     case 'betas'
15
-%         V=des.Vbeta;
16
-% end;
17
-
18
-% if USE_DRIVE_CHECK_HACK
19
-% if V(1).fname(1)~='D'
20
-%      for z=1:length(V) % Change Drive Letter - HACK!
21
-%       	V(z).fname(1) = 'D';
22
-%      end; 
23
-% end
24
-% end
25
-
26
-% if (~smoothed)
27
-%   for z=1:length(V) % Change smoothed Filename - HACK!
28
-%       % D:....SUBJECTID\session\swfanders...
29
-%       % D:....SUBJECTID\session\wfanders...
30
-%       tmp = findstr(filesep,V(z).fname);
31
-%       V(z).fname = strcat(V(z).fname(1:tmp(end)),V(z).fname(tmp(end)+2:end));
32
-%   end;
33
-% end
34 2
 
35 3
 V = filenameList;
36 4
 
... ...
@@ -39,66 +7,38 @@ nVoxel = size(vox,1);
39 7
 nImage = numel(V);
40 8
 
41 9
 for kImage=1:nImage
42
-% 	extr(kImage) = struct(...
43
-%         'dat',  ...
44
-%         'val',   repmat(NaN, [1 nVoxel]),...
45
-% 		'mean',  repmat(NaN, [1 nVoxel]),...
46
-% 		'sum',   repmat(NaN, [1 nVoxel]),...
47
-% 		'nvx',   repmat(NaN, [1 nVoxel]),...
48
-% 		'posmm', repmat(NaN, [3 nVoxel]),...
49
-% 		'posvx', repmat(NaN, [3 nVoxel]));
10
+    roicenter = round(inv(V(kImage).mat)*[vox, ones(nVoxel,1)]');
11
+    x = roicenter(1,:);
12
+    y = roicenter(2,:);
13
+    z = roicenter(3,:);
50 14
 
51
-    switch TRANSFORM_METHOD
52
-        case 'single'
53
-            roicenter = round(inv(V(kImage).mat)*[vox, ones(nVoxel,1)]');
54
-            x = roicenter(1,:);
55
-            y = roicenter(2,:);
56
-            z = roicenter(3,:);
57
-        case 'image'
58
-             x = []; y = []; z = [];
59
-            for iRoiFile = 1:nRoiFiles 
60
-                [x1 y1] = ndgrid(1:V(k).dim(1),1:V(k).dim(2));
61
-                for p = 1:V(k).dim(3) % resample mask Vm(iRoiFile) in space of V(k)
62
-                    B = spm_matrix([0 0 -p 0 0 0 1 1 1]);
63
-                    M = inv(B*inv(V(k).mat)*Vm(iRoiFile).mat);
64
-                    msk = find(spm_slice_vol(Vm(iRoiFile),M,V(k).dim(1:2),0));
65
-                    if ~isempty(msk)
66
-                        z1 = p*ones(size(msk(:)));
67
-                        x = [x; x1(msk(:))];
68
-                        y = [y; y1(msk(:))];
69
-                        z = [z; z1];
70
-                    end;
71
-                end;
72
-            end
73
-    end
74
-    
75 15
 
76
-	for iVoxel = 1:nVoxel
16
+    for iVoxel = 1:nVoxel
77 17
 
78
-%         if rad==0
18
+        if rad==0
79 19
             x = roicenter(1,iVoxel);
80 20
             y = roicenter(2,iVoxel);
81 21
             z = roicenter(3,iVoxel);
82
-%         else
83
-%             tmp = spm_imatrix(V(kImage).mat);
84
-%             vdim = tmp(7:9);
85
-%             vxrad = ceil((rad*ones(1,3))./(ones(nVoxel,1)*vdim))';
86
-%             [x y z] = ndgrid(-vxrad(1,iVoxel):sign(vdim(1)):vxrad(1,iVoxel), ...
87
-%                       -vxrad(2,iVoxel):sign(vdim(2)):vxrad(2,iVoxel), ...
88
-%                       -vxrad(3,iVoxel):sign(vdim(3)):vxrad(3,iVoxel));
89
-%             sel = (x./vxrad(1,iVoxel)).^2 + (y./vxrad(2,iVoxel)).^2 + ...
90
-%                   (z./vxrad(3,iVoxel)).^2 <= 1;
91
-%             x = roicenter(1,iVoxel)+x(sel(:));
92
-%             y = roicenter(2,iVoxel)+y(sel(:));
93
-%             z = roicenter(3,iVoxel)+z(sel(:));
94
-%         end;
95
-
96
-
97
-		dat = spm_sample_vol(V(kImage), x, y, z,0);
22
+        else
23
+            tmp = spm_imatrix(V(kImage).mat);
24
+            vdim = tmp(7:9);
25
+            vxrad = ceil((rad*ones(1,3))./(ones(nVoxel,1)*vdim))';
26
+            [x y z] = ndgrid(-vxrad(1,iVoxel):sign(vdim(1)):vxrad(1,iVoxel), ...
27
+                -vxrad(2,iVoxel):sign(vdim(2)):vxrad(2,iVoxel), ...
28
+                -vxrad(3,iVoxel):sign(vdim(3)):vxrad(3,iVoxel));
29
+            sel = (x./vxrad(1,iVoxel)).^2 + (y./vxrad(2,iVoxel)).^2 + ...
30
+                (z./vxrad(3,iVoxel)).^2 <= 1;
31
+            x = roicenter(1,iVoxel)+x(sel(:));
32
+            y = roicenter(2,iVoxel)+y(sel(:));
33
+            z = roicenter(3,iVoxel)+z(sel(:));
34
+        end;
35
+
36
+
37
+        dat = spm_sample_vol(V(kImage), x, y, z,0);
98 38
         extr(kImage).dat(iVoxel)      = dat;
99
-		extr(kImage).mean(iVoxel)     = nanmean(dat);
39
+        extr(kImage).mean(iVoxel)     = nanmean(dat);
100 40
         extr(kImage).nvx(iVoxel)      = numel(dat);
101
-	end;
41
+    end;
102 42
 
103 43
 end;
104 44
 end
105 45
\ No newline at end of file
Browse code

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@124 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on06/02/2009 11:51:00
Showing1 changed files
... ...
@@ -1,24 +1,52 @@
1
-% filenameList (e.g. as in SPM.xY.VY)
2
-% voxelList in [x y z], 1 coordinate per row, untransformed
1
+% filenameList as in SPM.xY.VY
2
+% voxelList in [x y z], 1 coordinate per row
3 3
 
4
-function extr = calculateImageData(filenameList, voxelList, imageOpts)
5
-TRANSFORM_METHOD = 'image';
4
+function extr = calculateImageData(filenameList, voxelList)
5
+TRANSFORM_METHOD = 'single';
6
+%function extr = calculateImageData(voxelList,des,smoothed)
7
+% global USE_DRIVE_CHECK_HACK;
8
+
9
+% dtype='PSTH';
10
+
11
+% switch dtype 
12
+%     case 'PSTH'
13
+%         V=des.xY.VY;
14
+%     case 'betas'
15
+%         V=des.Vbeta;
16
+% end;
17
+
18
+% if USE_DRIVE_CHECK_HACK
19
+% if V(1).fname(1)~='D'
20
+%      for z=1:length(V) % Change Drive Letter - HACK!
21
+%       	V(z).fname(1) = 'D';
22
+%      end; 
23
+% end
24
+% end
25
+
26
+% if (~smoothed)
27
+%   for z=1:length(V) % Change smoothed Filename - HACK!
28
+%       % D:....SUBJECTID\session\swfanders...
29
+%       % D:....SUBJECTID\session\wfanders...
30
+%       tmp = findstr(filesep,V(z).fname);
31
+%       V(z).fname = strcat(V(z).fname(1:tmp(end)),V(z).fname(tmp(end)+2:end));
32
+%   end;
33
+% end
6 34
 
7 35
 V = filenameList;
8 36
 
9 37
 vox = voxelList;
10 38
 nVoxel = size(vox,1);
11 39
 nImage = numel(V);
12
-nRoiFiles = ;
13 40
 
14 41
 for kImage=1:nImage
15
-    extr(kImage) = struct(...
16
-        'dat',   repmat(NaN, [1 nVoxel]),...
17
-        'mean',  repmat(NaN, [1 nVoxel]),...
18
-        'sum',   repmat(NaN, [1 nVoxel]),...
19
-        'nvx',   repmat(NaN, [1 nVoxel]),...
20
-        'posmm', repmat(NaN, [3 nVoxel]),...
21
-        'posvx', repmat(NaN, [3 nVoxel]));
42
+% 	extr(kImage) = struct(...
43
+%         'dat',  ...
44
+%         'val',   repmat(NaN, [1 nVoxel]),...
45
+% 		'mean',  repmat(NaN, [1 nVoxel]),...
46
+% 		'sum',   repmat(NaN, [1 nVoxel]),...
47
+% 		'nvx',   repmat(NaN, [1 nVoxel]),...
48
+% 		'posmm', repmat(NaN, [3 nVoxel]),...
49
+% 		'posvx', repmat(NaN, [3 nVoxel]));
22 50
 
23 51
     switch TRANSFORM_METHOD
24 52
         case 'single'
... ...
@@ -27,8 +55,8 @@ for kImage=1:nImage
27 55
             y = roicenter(2,:);
28 56
             z = roicenter(3,:);
29 57
         case 'image'
30
-            x = []; y = []; z = [];
31
-            for iRoiFile = 1:nRoiFiles
58
+             x = []; y = []; z = [];
59
+            for iRoiFile = 1:nRoiFiles 
32 60
                 [x1 y1] = ndgrid(1:V(k).dim(1),1:V(k).dim(2));
33 61
                 for p = 1:V(k).dim(3) % resample mask Vm(iRoiFile) in space of V(k)
34 62
                     B = spm_matrix([0 0 -p 0 0 0 1 1 1]);
... ...
@@ -43,11 +71,34 @@ for kImage=1:nImage
43 71
                 end;
44 72
             end
45 73
     end
74
+    
46 75
 
47
-    dat = spm_sample_vol(V(kImage), x, y, z,0);
48
-    extr(kImage).dat(iVoxel)      = dat;
49
-    extr(kImage).mean(iVoxel)     = nanmean(dat);
50
-    extr(kImage).nvx(iVoxel)      = numel(dat);
51
-end;
76
+	for iVoxel = 1:nVoxel
52 77
 
78
+%         if rad==0
79
+            x = roicenter(1,iVoxel);
80
+            y = roicenter(2,iVoxel);
81
+            z = roicenter(3,iVoxel);
82
+%         else
83
+%             tmp = spm_imatrix(V(kImage).mat);
84
+%             vdim = tmp(7:9);
85
+%             vxrad = ceil((rad*ones(1,3))./(ones(nVoxel,1)*vdim))';
86
+%             [x y z] = ndgrid(-vxrad(1,iVoxel):sign(vdim(1)):vxrad(1,iVoxel), ...
87
+%                       -vxrad(2,iVoxel):sign(vdim(2)):vxrad(2,iVoxel), ...
88
+%                       -vxrad(3,iVoxel):sign(vdim(3)):vxrad(3,iVoxel));
89
+%             sel = (x./vxrad(1,iVoxel)).^2 + (y./vxrad(2,iVoxel)).^2 + ...
90
+%                   (z./vxrad(3,iVoxel)).^2 <= 1;
91
+%             x = roicenter(1,iVoxel)+x(sel(:));
92
+%             y = roicenter(2,iVoxel)+y(sel(:));
93
+%             z = roicenter(3,iVoxel)+z(sel(:));
94
+%         end;
95
+
96
+
97
+		dat = spm_sample_vol(V(kImage), x, y, z,0);
98
+        extr(kImage).dat(iVoxel)      = dat;
99
+		extr(kImage).mean(iVoxel)     = nanmean(dat);
100
+        extr(kImage).nvx(iVoxel)      = numel(dat);
101
+	end;
102
+
103
+end;
53 104
 end
54 105
\ No newline at end of file
Browse code

heavy CrossVal Toolbox development. unusable snapshot!

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@123 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on03/02/2009 14:36:11
Showing1 changed files
... ...
@@ -1,50 +1,24 @@
1
-% filenameList as in SPM.xY.VY
2
-% voxelList in [x y z], 1 coordinate per row
1
+% filenameList (e.g. as in SPM.xY.VY)
2
+% voxelList in [x y z], 1 coordinate per row, untransformed
3 3
 
4
-function extr = calculateImageData(filenameList, voxelList)
5
-%function extr = calculateImageData(voxelList,des,smoothed)
6
-% global USE_DRIVE_CHECK_HACK;
7
-
8
-% dtype='PSTH';
9
-
10
-% switch dtype 
11
-%     case 'PSTH'
12
-%         V=des.xY.VY;
13
-%     case 'betas'
14
-%         V=des.Vbeta;
15
-% end;
16
-
17
-% if USE_DRIVE_CHECK_HACK
18
-% if V(1).fname(1)~='D'
19
-%      for z=1:length(V) % Change Drive Letter - HACK!
20
-%       	V(z).fname(1) = 'D';
21
-%      end; 
22
-% end
23
-% end
24
-
25
-% if (~smoothed)
26
-%   for z=1:length(V) % Change smoothed Filename - HACK!
27
-%       % D:....SUBJECTID\session\swfanders...
28
-%       % D:....SUBJECTID\session\wfanders...
29
-%       tmp = findstr(filesep,V(z).fname);
30
-%       V(z).fname = strcat(V(z).fname(1:tmp(end)),V(z).fname(tmp(end)+2:end));
31
-%   end;
32
-% end
4
+function extr = calculateImageData(filenameList, voxelList, imageOpts)
5
+TRANSFORM_METHOD = 'image';
33 6
 
34 7
 V = filenameList;
35 8
 
36 9
 vox = voxelList;
37 10
 nVoxel = size(vox,1);
38 11
 nImage = numel(V);
12
+nRoiFiles = ;
39 13
 
40 14
 for kImage=1:nImage
41
-	extr(kImage) = struct(...
42
-        'val',   repmat(NaN, [1 nVoxel]),...
43
-		'mean',  repmat(NaN, [1 nVoxel]),...
44
-		'sum',   repmat(NaN, [1 nVoxel]),...
45
-		'nvx',   repmat(NaN, [1 nVoxel]),...
46
-		'posmm', repmat(NaN, [3 nVoxel]),...
47
-		'posvx', repmat(NaN, [3 nVoxel]));
15
+    extr(kImage) = struct(...
16
+        'dat',   repmat(NaN, [1 nVoxel]),...
17
+        'mean',  repmat(NaN, [1 nVoxel]),...
18
+        'sum',   repmat(NaN, [1 nVoxel]),...
19
+        'nvx',   repmat(NaN, [1 nVoxel]),...
20
+        'posmm', repmat(NaN, [3 nVoxel]),...
21
+        'posvx', repmat(NaN, [3 nVoxel]));
48 22
 
49 23
     switch TRANSFORM_METHOD
50 24
         case 'single'
... ...
@@ -53,8 +27,8 @@ for kImage=1:nImage
53 27
             y = roicenter(2,:);
54 28
             z = roicenter(3,:);
55 29
         case 'image'
56
-             x = []; y = []; z = [];
57
-            for iRoiFile = 1:nRoiFiles 
30
+            x = []; y = []; z = [];
31
+            for iRoiFile = 1:nRoiFiles
58 32
                 [x1 y1] = ndgrid(1:V(k).dim(1),1:V(k).dim(2));
59 33
                 for p = 1:V(k).dim(3) % resample mask Vm(iRoiFile) in space of V(k)
60 34
                     B = spm_matrix([0 0 -p 0 0 0 1 1 1]);
... ...
@@ -67,37 +41,13 @@ for kImage=1:nImage
67 41
                         z = [z; z1];
68 42
                     end;
69 43
                 end;
70
-
71 44
             end
72 45
     end
73
-    
74
-
75
-	for iVoxel = 1:nVoxel
76
-
77
-%         if rad==0
78
-            x = roicenter(1,iVoxel);
79
-            y = roicenter(2,iVoxel);
80
-            z = roicenter(3,iVoxel);
81
-%         else
82
-%             tmp = spm_imatrix(V(kImage).mat);
83
-%             vdim = tmp(7:9);
84
-%             vxrad = ceil((rad*ones(1,3))./(ones(nVoxel,1)*vdim))';
85
-%             [x y z] = ndgrid(-vxrad(1,iVoxel):sign(vdim(1)):vxrad(1,iVoxel), ...
86
-%                       -vxrad(2,iVoxel):sign(vdim(2)):vxrad(2,iVoxel), ...
87
-%                       -vxrad(3,iVoxel):sign(vdim(3)):vxrad(3,iVoxel));
88
-%             sel = (x./vxrad(1,iVoxel)).^2 + (y./vxrad(2,iVoxel)).^2 + ...
89
-%                   (z./vxrad(3,iVoxel)).^2 <= 1;
90
-%             x = roicenter(1,iVoxel)+x(sel(:));
91
-%             y = roicenter(2,iVoxel)+y(sel(:));
92
-%             z = roicenter(3,iVoxel)+z(sel(:));
93
-%         end;
94
-
95
-
96
-		dat = spm_sample_vol(V(kImage), x, y, z,0);
97
-        extr(kImage).dat(iVoxel)      = dat;
98
-		extr(kImage).mean(iVoxel)     = nanmean(dat);
99
-        extr(kImage).nvx(iVoxel)      = numel(dat);
100
-	end;
101 46
 
47
+    dat = spm_sample_vol(V(kImage), x, y, z,0);
48
+    extr(kImage).dat(iVoxel)      = dat;
49
+    extr(kImage).mean(iVoxel)     = nanmean(dat);
50
+    extr(kImage).nvx(iVoxel)      = numel(dat);
102 51
 end;
52
+
103 53
 end
104 54
\ No newline at end of file
Browse code

refactored to arg-structs! (untested)

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@122 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on29/01/2009 16:25:27
Showing1 changed files
... ...
@@ -1,79 +1,102 @@
1
-function extr = calculateImageData(voxelList,des,smoothed)
1
+% filenameList as in SPM.xY.VY
2
+% voxelList in [x y z], 1 coordinate per row
2 3
 
3
-dtype='PSTH';
4
+function extr = calculateImageData(filenameList, voxelList)
5
+%function extr = calculateImageData(voxelList,des,smoothed)
6
+% global USE_DRIVE_CHECK_HACK;
4 7
 
5
-switch dtype 
6
-    case 'PSTH'
7
-        V=des.xY.VY;
8
-    case 'betas'
9
-        V=des.Vbeta;
10
-end;
8
+% dtype='PSTH';
11 9
 
12
-if V(1).fname(1)~='D'
13
-     for z=1:length(V) % Change Drive Letter!\
14
-      	V(z).fname(1) = 'D';
15
-     end; 
16
-end
10
+% switch dtype 
11
+%     case 'PSTH'
12
+%         V=des.xY.VY;
13
+%     case 'betas'
14
+%         V=des.Vbeta;
15
+% end;
17 16
 
18
-if (~smoothed)
19
-  for z=1:length(V) % Change Drive Letter!\
20
-      % D:....SUBJECTID\session\swfanders...
21
-      % D:....SUBJECTID\session\wfanders...
22
-      tmp = findstr(filesep,V(z).fname);
23
-      V(z).fname = strcat(V(z).fname(1:tmp(end)),V(z).fname(tmp(end)+2:end));
24
-  end;
25
-end
17
+% if USE_DRIVE_CHECK_HACK
18
+% if V(1).fname(1)~='D'
19
+%      for z=1:length(V) % Change Drive Letter - HACK!
20
+%       	V(z).fname(1) = 'D';
21
+%      end; 
22
+% end
23
+% end
26 24
 
27
-% rad = 0; % one voxel
28
-% opt = 1; % xyz coordinates [mm]
25
+% if (~smoothed)
26
+%   for z=1:length(V) % Change smoothed Filename - HACK!
27
+%       % D:....SUBJECTID\session\swfanders...
28
+%       % D:....SUBJECTID\session\wfanders...
29
+%       tmp = findstr(filesep,V(z).fname);
30
+%       V(z).fname = strcat(V(z).fname(1:tmp(end)),V(z).fname(tmp(end)+2:end));
31
+%   end;
32
+% end
29 33
 
34
+V = filenameList;
30 35
 
31 36
 vox = voxelList;
32
-nRoi = size(vox,1);
37
+nVoxel = size(vox,1);
38
+nImage = numel(V);
33 39
 
34
-nImg = numel(V);
40
+for kImage=1:nImage
41
+	extr(kImage) = struct(...
42
+        'val',   repmat(NaN, [1 nVoxel]),...
43
+		'mean',  repmat(NaN, [1 nVoxel]),...
44
+		'sum',   repmat(NaN, [1 nVoxel]),...
45
+		'nvx',   repmat(NaN, [1 nVoxel]),...
46
+		'posmm', repmat(NaN, [3 nVoxel]),...
47
+		'posvx', repmat(NaN, [3 nVoxel]));
35 48
 
36
-for k=1:nImg
37
-	extr(k) = struct(...
38
-        'val',   repmat(NaN, [1 nRoi]),...
39
-		'mean',  repmat(NaN, [1 nRoi]),...
40
-		'sum',   repmat(NaN, [1 nRoi]),...
41
-		'nvx',   repmat(NaN, [1 nRoi]),...
42
-		'posmm', repmat(NaN, [3 nRoi]),...
43
-		'posvx', repmat(NaN, [3 nRoi]));
49
+    switch TRANSFORM_METHOD
50
+        case 'single'
51
+            roicenter = round(inv(V(kImage).mat)*[vox, ones(nVoxel,1)]');
52
+            x = roicenter(1,:);
53
+            y = roicenter(2,:);
54
+            z = roicenter(3,:);
55
+        case 'image'
56
+             x = []; y = []; z = [];
57
+            for iRoiFile = 1:nRoiFiles 
58
+                [x1 y1] = ndgrid(1:V(k).dim(1),1:V(k).dim(2));
59
+                for p = 1:V(k).dim(3) % resample mask Vm(iRoiFile) in space of V(k)
60
+                    B = spm_matrix([0 0 -p 0 0 0 1 1 1]);
61
+                    M = inv(B*inv(V(k).mat)*Vm(iRoiFile).mat);
62
+                    msk = find(spm_slice_vol(Vm(iRoiFile),M,V(k).dim(1:2),0));
63
+                    if ~isempty(msk)
64
+                        z1 = p*ones(size(msk(:)));
65
+                        x = [x; x1(msk(:))];
66
+                        y = [y; y1(msk(:))];
67
+                        z = [z; z1];
68
+                    end;
69
+                end;
44 70
 
45
-    roicenter = round(inv(V(k).mat)*[vox, ones(nRoi,1)]');
71
+            end
72
+    end
73
+    
46 74
 
47
-	for l = 1:nRoi
75
+	for iVoxel = 1:nVoxel
48 76
 
49 77
 %         if rad==0
50
-            x = roicenter(1,l);
51
-            y = roicenter(2,l);
52
-            z = roicenter(3,l);
78
+            x = roicenter(1,iVoxel);
79
+            y = roicenter(2,iVoxel);
80
+            z = roicenter(3,iVoxel);
53 81
 %         else
54
-%             tmp = spm_imatrix(V(k).mat);
82
+%             tmp = spm_imatrix(V(kImage).mat);
55 83
 %             vdim = tmp(7:9);
56
-%             vxrad = ceil((rad*ones(1,3))./(ones(nRoi,1)*vdim))';
57
-%             [x y z] = ndgrid(-vxrad(1,l):sign(vdim(1)):vxrad(1,l), ...
58
-%                       -vxrad(2,l):sign(vdim(2)):vxrad(2,l), ...
59
-%                       -vxrad(3,l):sign(vdim(3)):vxrad(3,l));
60
-%             sel = (x./vxrad(1,l)).^2 + (y./vxrad(2,l)).^2 + ...
61
-%                   (z./vxrad(3,l)).^2 <= 1;
62
-%             x = roicenter(1,l)+x(sel(:));
63
-%             y = roicenter(2,l)+y(sel(:));
64
-%             z = roicenter(3,l)+z(sel(:));
84
+%             vxrad = ceil((rad*ones(1,3))./(ones(nVoxel,1)*vdim))';
85
+%             [x y z] = ndgrid(-vxrad(1,iVoxel):sign(vdim(1)):vxrad(1,iVoxel), ...
86
+%                       -vxrad(2,iVoxel):sign(vdim(2)):vxrad(2,iVoxel), ...
87
+%                       -vxrad(3,iVoxel):sign(vdim(3)):vxrad(3,iVoxel));
88
+%             sel = (x./vxrad(1,iVoxel)).^2 + (y./vxrad(2,iVoxel)).^2 + ...
89
+%                   (z./vxrad(3,iVoxel)).^2 <= 1;
90
+%             x = roicenter(1,iVoxel)+x(sel(:));
91
+%             y = roicenter(2,iVoxel)+y(sel(:));
92
+%             z = roicenter(3,iVoxel)+z(sel(:));
65 93
 %         end;
66 94
 
67 95
 
68
-		dat                 = spm_sample_vol(V(k), x, y, z,0);
69
-		[maxv maxi]         = max(dat);
70
-		tmp                 = V(k).mat*[x(maxi); y(maxi); z(maxi);1]; % Max Pos
71
-		extr(k).val(l)      = maxv;
72
-		extr(k).sum(l)      = sum(dat);
73
-		extr(k).mean(l)     = nanmean(dat);
74
-        extr(k).nvx(l)      = numel(dat);
75
-		extr(k).posmm(:,l)  = tmp(1:3);
76
-		extr(k).posvx(:,l)  = [x(maxi); y(maxi); z(maxi)]; % Max Pos
96
+		dat = spm_sample_vol(V(kImage), x, y, z,0);
97
+        extr(kImage).dat(iVoxel)      = dat;
98
+		extr(kImage).mean(iVoxel)     = nanmean(dat);
99
+        extr(kImage).nvx(iVoxel)      = numel(dat);
77 100
 	end;
78 101
 
79 102
 end;
Browse code

kleine änderungen code move

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@102 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on08/01/2009 11:44:25
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,80 @@
1
+function extr = calculateImageData(voxelList,des,smoothed)
2
+
3
+dtype='PSTH';
4
+
5
+switch dtype 
6
+    case 'PSTH'
7
+        V=des.xY.VY;
8
+    case 'betas'
9
+        V=des.Vbeta;
10
+end;
11
+
12
+if V(1).fname(1)~='D'
13
+     for z=1:length(V) % Change Drive Letter!\
14
+      	V(z).fname(1) = 'D';
15
+     end; 
16
+end
17
+
18
+if (~smoothed)
19
+  for z=1:length(V) % Change Drive Letter!\
20
+      % D:....SUBJECTID\session\swfanders...
21
+      % D:....SUBJECTID\session\wfanders...
22
+      tmp = findstr(filesep,V(z).fname);
23
+      V(z).fname = strcat(V(z).fname(1:tmp(end)),V(z).fname(tmp(end)+2:end));
24
+  end;
25
+end
26
+
27
+% rad = 0; % one voxel
28
+% opt = 1; % xyz coordinates [mm]
29
+
30
+
31
+vox = voxelList;
32
+nRoi = size(vox,1);
33
+
34
+nImg = numel(V);
35
+
36
+for k=1:nImg
37
+	extr(k) = struct(...
38
+        'val',   repmat(NaN, [1 nRoi]),...
39
+		'mean',  repmat(NaN, [1 nRoi]),...
40
+		'sum',   repmat(NaN, [1 nRoi]),...
41
+		'nvx',   repmat(NaN, [1 nRoi]),...
42
+		'posmm', repmat(NaN, [3 nRoi]),...
43
+		'posvx', repmat(NaN, [3 nRoi]));
44
+
45
+    roicenter = round(inv(V(k).mat)*[vox, ones(nRoi,1)]');
46
+
47
+	for l = 1:nRoi
48
+
49
+%         if rad==0
50
+            x = roicenter(1,l);
51
+            y = roicenter(2,l);
52
+            z = roicenter(3,l);
53
+%         else
54
+%             tmp = spm_imatrix(V(k).mat);
55
+%             vdim = tmp(7:9);
56
+%             vxrad = ceil((rad*ones(1,3))./(ones(nRoi,1)*vdim))';
57
+%             [x y z] = ndgrid(-vxrad(1,l):sign(vdim(1)):vxrad(1,l), ...
58
+%                       -vxrad(2,l):sign(vdim(2)):vxrad(2,l), ...
59
+%                       -vxrad(3,l):sign(vdim(3)):vxrad(3,l));
60
+%             sel = (x./vxrad(1,l)).^2 + (y./vxrad(2,l)).^2 + ...
61
+%                   (z./vxrad(3,l)).^2 <= 1;
62
+%             x = roicenter(1,l)+x(sel(:));
63
+%             y = roicenter(2,l)+y(sel(:));
64
+%             z = roicenter(3,l)+z(sel(:));
65
+%         end;
66
+
67
+
68
+		dat                 = spm_sample_vol(V(k), x, y, z,0);
69
+		[maxv maxi]         = max(dat);
70
+		tmp                 = V(k).mat*[x(maxi); y(maxi); z(maxi);1]; % Max Pos
71
+		extr(k).val(l)      = maxv;
72
+		extr(k).sum(l)      = sum(dat);
73
+		extr(k).mean(l)     = nanmean(dat);
74
+        extr(k).nvx(l)      = numel(dat);
75
+		extr(k).posmm(:,l)  = tmp(1:3);
76
+		extr(k).posvx(:,l)  = [x(maxi); y(maxi); z(maxi)]; % Max Pos
77
+	end;
78
+
79
+end;
80
+end
0 81
\ No newline at end of file