2e65fc12d407ef0d460c1de6b2818f9e4f94b000
Christoph Budziszewski heavy CrossVal Toolbox deve...

Christoph Budziszewski authored 15 years ago

1) function coordinateStruct = computeCoordinates(imageStruct)
2) %imageStruct.(someName).images
3) %imageStruct.(someName).roiImages
4) coordinateStruct = struct;
5) 
6) subjectCellList = fieldnames(imageStruct);
7) 
8) for subject = 1:length(subjectCellList)
9)     subjectFieldName = cell2mat(subjectCellList(subject));
10)     % ROI Image Coordinates
11)     V  = imageStruct.(subjectFieldName).images;
12)     Vm = imageStruct.(subjectFieldName).roiImages;
13)     coordinateStruct.(subjectFieldName) = ...
14)         computeRoiImageCoordinates(V,Vm);
15)     % Parsed Voxel Definitions
16)     coordinateStruct.(subjectFieldName) = ...
17)         appendManualVoxelCoordinates(coordinateStruct.(subjectFieldName),V);
18)     
19) end
20) end
21) 
22) function coordinates = appendManualVoxelCoordinates(coordinateStruct,V)
23)     coordinates =coordinateStruct;
24) end
25) 
26) function coordinates = computeRoiImageCoordinates(V,Vm)
27)     nVolImage = length(V);
28)     nRoiImage = length(Vm);
29)     
30)     coordinates = cell(nVolImage,1);
31)  
32)     for iVolImage = 1:nVolImage
33)         coordinates{iVolImage} = [];
34)         for jRoiImage = 1:nRoiImage
Christoph Budziszewski possibly working version, c...

Christoph Budziszewski authored 15 years ago

35)             [x,y,z] = computeCoordinateVector(V(iVolImage),Vm(jRoiImage));
36)             coordinates{iVolImage} = [coordinates{iVolImage}; x, y, z];
37)         end
38)     end
39) end
40) 
41) function [x,y,z] = computeCoordinateVector(VolumeImage,RoiImage)
Christoph Budziszewski heavy CrossVal Toolbox deve...

Christoph Budziszewski authored 15 years ago

42)             x = []; y = []; z = [];
Christoph Budziszewski possibly working version, c...

Christoph Budziszewski authored 15 years ago

43)             [x1 y1] = ndgrid(1:VolumeImage.dim(1),1:VolumeImage.dim(2));
44)             for p = 1:VolumeImage.dim(3) % resample mask RoiImage in space of VolumeImage
Christoph Budziszewski heavy CrossVal Toolbox deve...

Christoph Budziszewski authored 15 years ago

45)                 B = spm_matrix([0 0 -p 0 0 0 1 1 1]);
Christoph Budziszewski possibly working version, c...

Christoph Budziszewski authored 15 years ago

46)                 M = inv(B*inv(VolumeImage.mat)*RoiImage.mat);
47)                 msk = find(spm_slice_vol(RoiImage,M,VolumeImage.dim(1:2),0));
Christoph Budziszewski heavy CrossVal Toolbox deve...

Christoph Budziszewski authored 15 years ago

48)                 if ~isempty(msk)
49)                     z1 = p*ones(size(msk(:)));
50)                     x = [x; x1(msk(:))];
51)                     y = [y; y1(msk(:))];
52)                     z = [z; z1];
53)                 end;
54)             end;