Home > SurfStat > SurfStatVol2Surf.m

SurfStatVol2Surf

PURPOSE ^

Interpolates a volume to each surface, then averages.

SYNOPSIS ^

function s = SurfStatVol2Surf( vol, surf );

DESCRIPTION ^

Interpolates a volume to each surface, then averages. 

 Usage: s = SurfStatVol2Surf( vol, surfs );

 vol.data   = nx x ny x nz volume aligned to the surface data.
 vol.origin = [x,y,z] location of vol.data(1,1,1) in mm.
 vol.vox    = [x,y,z] voxel size in mm.
 surf.coord = 3 x v matrix of coordinates in mm, v=#vertices, in double
              precision, if n=1; or n x v x 3 in single precision if n>1,
              or memory map of same.

 s = 1 x v vector of vol.data interpolated to each surface, then averaged.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function s = SurfStatVol2Surf( vol, surf );
0002 
0003 %Interpolates a volume to each surface, then averages.
0004 %
0005 % Usage: s = SurfStatVol2Surf( vol, surfs );
0006 %
0007 % vol.data   = nx x ny x nz volume aligned to the surface data.
0008 % vol.origin = [x,y,z] location of vol.data(1,1,1) in mm.
0009 % vol.vox    = [x,y,z] voxel size in mm.
0010 % surf.coord = 3 x v matrix of coordinates in mm, v=#vertices, in double
0011 %              precision, if n=1; or n x v x 3 in single precision if n>1,
0012 %              or memory map of same.
0013 %
0014 % s = 1 x v vector of vol.data interpolated to each surface, then averaged.
0015 
0016 if isnumeric(surf.coord)
0017     v=size(surf.coord,2);
0018     one=ones(v,1);
0019     if ndims(surf.coord)==2
0020         vox=(double(surf.coord')-one*vol.origin)./(one*vol.vox(1:3))+1;
0021         s=interpn(vol.data,vox(:,1),vox(:,2),vox(:,3),'linear',0);
0022     else
0023         n=size(surf.coord,1);
0024         s=zeros(v,1);
0025         fprintf(1,'%s',[num2str(n) ' surfaces to interpolate, % remaining: 100 ']);
0026         n10=floor(n/10);
0027         for i=1:n
0028             if rem(i,n10)==0
0029                 fprintf(1,'%s',[num2str(round(100*(1-i/n))) ' ']);
0030             end
0031             c=double(squeeze(surf.coord(i,:,:)));
0032             vox=(c-one*vol.origin)./(one*vol.vox(1:3))+1;
0033             s=s+interpn(vol.data,vox(:,1),vox(:,2),vox(:,3),'linear',0);
0034         end
0035         s=s'/n;
0036         fprintf(1,'%s\n','Done');
0037     end
0038 else
0039     sz=surf.coord.Format{2};
0040     v=sz(1);
0041     n=sz(3);
0042     one=ones(v,1);
0043     s=zeros(v,1);
0044     fprintf(1,'%s',[num2str(n) ' surfaces to interpolate, % remaining: 100 ']);
0045     n10=floor(n/10);
0046     for i=1:n
0047         if rem(i,n10)==0
0048             fprintf(1,'%s',[num2str(round(100*(1-i/n))) ' ']);
0049         end
0050         c=double(surf.coord.Data(1).Data(:,:,i));
0051         vox=(c-one*vol.origin)./(one*vol.vox(1:3))+1;
0052         s=s+interpn(vol.data,vox(:,1),vox(:,2),vox(:,3),'linear',0);
0053     end
0054     s=s'/n;
0055     fprintf(1,'%s\n','Done');
0056 end
0057 
0058 return
0059 end

Generated on Fri 26-Sep-2008 14:05:29 by m2html © 2003