private/calculateImageData.m
aa0fb379
 function [extr voxelcount] = calculateImageData(filenameList, coordlist,gFkt)
aa21d53b
 
aa0fb379
 %center coordinates
aa21d53b
 vox = [];
 nCoords = size(coordlist,1);
 for iCoord = 1:nCoords
    vox = [vox ; coordlist(iCoord).coord];
 end
 
aa0fb379
 %maximum extracted voxels over all images
17f70357
 voxelcount = 0;
9478fa59
 
c54095b9
 V = filenameList;
 nImage = numel(V);
aa21d53b
 nVoxel = nCoords;
c54095b9
 for kImage=1:nImage
e0049736
     roicenter = round(inv(V(kImage).mat)*[vox, ones(nVoxel,1)]');
9478fa59
 
17f70357
     subvoxelcount = 0;
e0049736
     for iVoxel = 1:nVoxel
07662323
 
aa0fb379
         %radius
aa21d53b
         rad = coordlist(iVoxel).rad;
aa0fb379
 
aa21d53b
         tmp = spm_imatrix(V(kImage).mat);
         vdim = tmp(7:9);
         vxrad = ceil((rad*ones(nVoxel,3))./(ones(nVoxel,1)*vdim))';
         
e0049736
         if rad==0
c2dab886
             x = roicenter(1,iVoxel);
             y = roicenter(2,iVoxel);
             z = roicenter(3,iVoxel);
e0049736
         else
             [x y z] = ndgrid(-vxrad(1,iVoxel):sign(vdim(1)):vxrad(1,iVoxel), ...
                 -vxrad(2,iVoxel):sign(vdim(2)):vxrad(2,iVoxel), ...
                 -vxrad(3,iVoxel):sign(vdim(3)):vxrad(3,iVoxel));
             sel = (x./vxrad(1,iVoxel)).^2 + (y./vxrad(2,iVoxel)).^2 + ...
                 (z./vxrad(3,iVoxel)).^2 <= 1;
             x = roicenter(1,iVoxel)+x(sel(:));
             y = roicenter(2,iVoxel)+y(sel(:));
             z = roicenter(3,iVoxel)+z(sel(:));
17910a1f
 %             [x y z]
e0049736
         end;
 
         dat = spm_sample_vol(V(kImage), x, y, z,0);
aa0fb379
  
         %%Implement Spatial grouping here
         
         dat = gFkt(dat);
daadf09b
         
aa0fb379
         % no grouping
17f70357
         for iSubVoxel = 1:size(dat,1)
             subvoxelcount = subvoxelcount +1;
             extr(kImage).dat(subvoxelcount)    = dat(iSubVoxel);
         end
aa0fb379
         
17f70357
     end
     voxelcount = max(voxelcount,subvoxelcount);
 end   
c2dab886
 
9478fa59
 end