


Read in entire image volumes FORMAT [Y,XYZ] = spm_read_vols(V,mask) V - vector of mapped image volumes to read in (from spm_vol) mask - implicit zero mask? Y - 4D matrix of image data, fourth dimension indexes images XYZ - 3xn matrix of XYZ locations returned _______________________________________________________________________ For image data types without a representation of NaN (see spm_type), implicit zero masking can be used. If mask is set, then zeros are treated as masked, and returned as NaN. _______________________________________________________________________ Copyright (C) 2005 Wellcome Department of Imaging Neuroscienic_e



0001 function [Y,XYZ] = nic_spm_read_vols(V,mask) 0002 % Read in entire image volumes 0003 % FORMAT [Y,XYZ] = spm_read_vols(V,mask) 0004 % V - vector of mapped image volumes to read in (from spm_vol) 0005 % mask - implicit zero mask? 0006 % Y - 4D matrix of image data, fourth dimension indexes images 0007 % XYZ - 3xn matrix of XYZ locations returned 0008 %_______________________________________________________________________ 0009 % 0010 % For image data types without a representation of NaN (see spm_type), 0011 % implicit zero masking can be used. If mask is set, then zeros are 0012 % treated as masked, and returned as NaN. 0013 %_______________________________________________________________________ 0014 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscienic_e 0015 0016 % Andrew Holmes 0017 % $Id: spm_read_vols.m 401 2006-01-12 12:10:17Z john $ 0018 0019 0020 0021 %-Argument checks 0022 %----------------------------------------------------------------------- 0023 if nargin<2, mask = 0; end 0024 if nargin<1, error('insufficient arguments'), end 0025 0026 %-Image dimension, orientation and voxel size checks 0027 %----------------------------------------------------------------------- 0028 if length(V)>1 & any(any(diff(cat(1,V.dim),1,1),1)) 0029 error('images don''t all have the same dimensions'), end 0030 if any(any(any(diff(cat(3,V.mat),1,3),3))) 0031 error('images don''t all have same orientation & voxel size'), end 0032 0033 %-Read in image data 0034 %----------------------------------------------------------------------- 0035 n = prod(size(V)); %-#images 0036 Y = zeros([V(1).dim(1:3),n]); %-image data matrix 0037 0038 for i=1:n, for p=1:V(1).dim(3) 0039 Y(:,:,p,i) = nic_spm_slice_vol(V(i),nic_spm_matrix([0 0 p]),V(i).dim(1:2), 0); 0040 end, end 0041 0042 %-Apply implicit zero mask for image datatypes without a NaNrep 0043 %----------------------------------------------------------------------- 0044 if mask 0045 %-Work out images without NaNrep 0046 im = logical(zeros(n,1)); 0047 for i=1:n, im(i)=~nic_spm_type(V(i).dt(1),'NaNrep'); end 0048 %-Mask 0049 Y(Y(:,:,:,im)==0)=NaN; 0050 end 0051 0052 %-Return as 3D matrix if single image 0053 %----------------------------------------------------------------------- 0054 if n==1; Y=Y(:,:,:,1); end 0055 0056 %-Compute XYZ co-ordinates (if required) 0057 %----------------------------------------------------------------------- 0058 if nargout>1 0059 [R,C,P]=ndgrid(1:V(1).dim(1),1:V(1).dim(2),1:V(1).dim(3)); 0060 RCP = [R(:)';C(:)';P(:)']; 0061 clear R C P 0062 RCP(4,:)=1; 0063 XYZ = V(1).mat(1:3,:)*RCP; 0064 end