Home > SurfStat > SurfStatAvVol.m

SurfStatAvVol

PURPOSE ^

Average, minimum or maximum of MINC, ANALYZE, NIFTI or AFNI volumes.

SYNOPSIS ^

function [ data, vol ] = SurfStatAvVol( filenames, fun, Nan );

DESCRIPTION ^

Average, minimum or maximum of MINC, ANALYZE, NIFTI or AFNI volumes.

 Usage: [ data, vol ] = SurfStatAvVol( filenames [, fun [, Nan ]]);

 filenames = file name with extension .mnc, .img, .nii or .brik as above 
             (n=1), or n x 1 cell array of file names.
 fun       = function handle to apply to two volumes, e.g. 
           = @plus (default) will give the average of the volumes,
           = @min or @max will give the min or max, respectively.
 Nan       = value to replace NaN in data, default NaN.

 data       = nx x ny x nz array of average, min or max volume.
 vol.lat    = logical(ones(nx,ny,nz)) (this is needed for SurfStatView1).
 vol.vox    = 1 x 3 vector of voxel sizes in mm.
 vol.origin = position in mm of the first voxel.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ data, vol ] = SurfStatAvVol( filenames, fun, Nan );
0002 
0003 %Average, minimum or maximum of MINC, ANALYZE, NIFTI or AFNI volumes.
0004 %
0005 % Usage: [ data, vol ] = SurfStatAvVol( filenames [, fun [, Nan ]]);
0006 %
0007 % filenames = file name with extension .mnc, .img, .nii or .brik as above
0008 %             (n=1), or n x 1 cell array of file names.
0009 % fun       = function handle to apply to two volumes, e.g.
0010 %           = @plus (default) will give the average of the volumes,
0011 %           = @min or @max will give the min or max, respectively.
0012 % Nan       = value to replace NaN in data, default NaN.
0013 %
0014 % data       = nx x ny x nz array of average, min or max volume.
0015 % vol.lat    = logical(ones(nx,ny,nz)) (this is needed for SurfStatView1).
0016 % vol.vox    = 1 x 3 vector of voxel sizes in mm.
0017 % vol.origin = position in mm of the first voxel.
0018 
0019 if nargin<2 | isempty(fun)
0020     fun=@plus;
0021 end
0022 if nargin<3
0023     Nan=NaN;
0024 end
0025 
0026 n=size(filenames,1);
0027 
0028 if n==1
0029     d=SurfStatReadVol1(filenames);
0030     data=d.data;
0031 else
0032     fprintf(1,'%s',[num2str(n) ' files to read, % remaining: 100 ']);
0033     n10=floor(n/10);
0034     for i=1:n
0035         if rem(i,n10)==0 
0036             fprintf(1,'%s',[num2str(round(100*(1-i/n))) ' ']);
0037         end
0038         d=SurfStatReadVol1(filenames{i});
0039         if ~isnan(Nan)
0040             d.data(isnan(d.data))=Nan;
0041         end
0042         if i==1
0043             data=d.data;
0044             m=1;
0045         else
0046             data=fun(data,d.data);
0047             m=fun(m,1);
0048         end
0049     end
0050     fprintf(1,'%s\n','Done');
0051 end
0052 data=data/m;
0053 vol.lat=logical(ones(d.dim(1:3)));
0054 vol.vox=d.vox(1:3);
0055 vol.origin=d.origin;
0056 
0057 return
0058 end

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