Home > SurfStat > SurfStatSurf2Vol.m

SurfStatSurf2Vol

PURPOSE ^

Interpolates data on each surface to a volume, then averages.

SYNOPSIS ^

function vol = SurfStatSurf2Vol( s, surf, template );

DESCRIPTION ^

Interpolates data on each surface to a volume, then averages. 

 Usage: vol = SurfStatSurf2Vol( s, surf [, template] );

 s          = 1 x v vector of surface data, v=#vertices.
 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.
 template   = template volume file, icbm_template_2.00mm.mnc by default. 
              For ANALYZE format use icbm_template_2.00mm.img,
              for NIFTI   format use icbm_template_2.00mm.nii,
              for AFNI    format use icbm_template_2.00mm.brik.

 vol.data   = nx x ny x nz array; for each surf.coord, s is assigned to 
              the nearest voxel in vol.data, then averaged over surfaces.
 vol.origin = [x,y,z] location of vol.data(1,1,1) in mm.
 vol.vox    = [x,y,z] voxel size in mm.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function vol = SurfStatSurf2Vol( s, surf, template );
0002 
0003 %Interpolates data on each surface to a volume, then averages.
0004 %
0005 % Usage: vol = SurfStatSurf2Vol( s, surf [, template] );
0006 %
0007 % s          = 1 x v vector of surface data, v=#vertices.
0008 % surf.coord = 3 x v matrix of coordinates in mm, v=#vertices, in double
0009 %              precision, if n=1; or n x v x 3 in single precision if n>1,
0010 %              or memory map of same.
0011 % template   = template volume file, icbm_template_2.00mm.mnc by default.
0012 %              For ANALYZE format use icbm_template_2.00mm.img,
0013 %              for NIFTI   format use icbm_template_2.00mm.nii,
0014 %              for AFNI    format use icbm_template_2.00mm.brik.
0015 %
0016 % vol.data   = nx x ny x nz array; for each surf.coord, s is assigned to
0017 %              the nearest voxel in vol.data, then averaged over surfaces.
0018 % vol.origin = [x,y,z] location of vol.data(1,1,1) in mm.
0019 % vol.vox    = [x,y,z] voxel size in mm.
0020 
0021 if nargin<3
0022     template='icbm_template_2.00mm.mnc';
0023 end
0024 
0025 vol=SurfStatReadVol1(template);
0026 [nx,ny,nz]=size(vol.data);
0027 
0028 if isnumeric(surf.coord)
0029     v=size(surf.coord,2);
0030     one=ones(v,1);
0031     if ndims(surf.coord)==2
0032         vox=round((double(surf.coord')-one*vol.origin)./(one*vol.vox(1:3))+1);
0033         in=vox(:,1)>=1&vox(:,2)>=1&vox(:,3)>=1;
0034         in=in&vox(:,1)<=nx&vox(:,2)<=ny&vox(:,3)<=nz;
0035         vol.data=accumarray(vox(in,:),s(in),[nx,ny,nz]);
0036         ns=accumarray(vox(in,:),1,[nx,ny,nz]);
0037         vol.data=vol.data./(ns+(ns<=0)).*(ns>0);
0038     else
0039         n=size(surf.coord,1);
0040         ns=zeros([nx,ny,nz]);
0041         fprintf(1,'%s',[num2str(n) ' surfaces to interpolate, % remaining: 100 ']);
0042         n10=floor(n/10);
0043         for i=1:n
0044             if rem(i,n10)==0
0045                 fprintf(1,'%s',[num2str(round(100*(1-i/n))) ' ']);
0046             end
0047             c=double(squeeze(surf.coord(i,:,:)));
0048             vox=round((c-one*vol.origin)./(one*vol.vox(1:3))+1);
0049             in=vox(:,1)>=1&vox(:,2)>=1&vox(:,3)>=1;
0050             in=in&vox(:,1)<=nx&vox(:,2)<=ny&vox(:,3)<=nz;
0051             vs=accumarray(vox(in,:),s(in),[nx,ny,nz]);
0052             ns=accumarray(vox(in,:),1,[nx,ny,nz]);
0053             vol.data=vol.data+vs./(ns+(ns<=0)).*(ns>0);
0054         end
0055         vol.data=vol.data/n;
0056         fprintf(1,'%s\n','Done');
0057     end
0058     vol.file_name=inputname(1);
0059 else
0060     sz=surf.coord.Format{2};
0061     v=sz(1);
0062     n=sz(3);
0063     one=ones(v,1);
0064     ns=zeros([nx,ny,nz]);
0065     fprintf(1,'%s',[num2str(n) ' surfaces to interpolate, % remaining: 100 ']);
0066     n10=floor(n/10);
0067     for i=1:n
0068         if rem(i,n10)==0
0069             fprintf(1,'%s',[num2str(round(100*(1-i/n))) ' ']);
0070         end
0071         c=double(surf.coord.Data(1).Data(:,:,i));
0072         vox=round((c-one*vol.origin)./(one*vol.vox(1:3))+1);
0073         in=vox(:,1)>=1&vox(:,2)>=1&vox(:,3)>=1;
0074         in=in&vox(:,1)<=nx&vox(:,2)<=ny&vox(:,3)<=nz;
0075         vs=accumarray(vox(in,:),s(in),[nx,ny,nz]);
0076         ns=accumarray(vox(in,:),1,[nx,ny,nz]);
0077         vol.data=vol.data+vs./(ns+(ns<=0)).*(ns>0);
0078     end
0079     vol.data=vol.data/n;
0080     fprintf(1,'%s\n','Done');
0081     vol.file_name=inputname(1);
0082 end    
0083     
0084 return
0085 end

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