takes XYZ matrix and values, returns SPM matrix vol struct FORMAT vol = pr_blobs2vol(xyz,vals,mat) Inputs xyz - 3xN X Y Z coordinate matrix (in voxels) vals - 1xN values, one per coordinate mat - 4x4 voxel->world space transformation Outputs vol - vol struct, with matrix data 'imgdata' field $Id: pr_blobs2vol.m,v 1.1 2005/04/20 15:05:00 matthewbrett Exp $
0001 function vol = pr_blobs2vol(xyz,vals,mat) 0002 % takes XYZ matrix and values, returns SPM matrix vol struct 0003 % FORMAT vol = pr_blobs2vol(xyz,vals,mat) 0004 % 0005 % Inputs 0006 % xyz - 3xN X Y Z coordinate matrix (in voxels) 0007 % vals - 1xN values, one per coordinate 0008 % mat - 4x4 voxel->world space transformation 0009 % 0010 % Outputs 0011 % vol - vol struct, with matrix data 'imgdata' field 0012 % 0013 % $Id: pr_blobs2vol.m,v 1.1 2005/04/20 15:05:00 matthewbrett Exp $ 0014 0015 if nargin < 3 0016 error('Need XYZ, vals and mat'); 0017 end 0018 0019 vol = []; 0020 if ~isempty(xyz), 0021 rcp = round(xyz); 0022 vol.dim = max(rcp,[],2)'; 0023 off = rcp(1,:) + vol.dim(1)*(rcp(2,:)-1+vol.dim(2)*(rcp(3,:)-1)); 0024 vol.imgdata = zeros(vol.dim)+NaN; 0025 vol.imgdata(off) = vals; 0026 vol.imgdata = reshape(vol.imgdata,vol.dim); 0027 vol.mat = mat; 0028 end 0029 return 0030