Create a 3D volume of sz and place vals at the coord positions vol3d = feValues2volume(stat,coords,vSize) save the vals in the correct locations inside the image volume. vals - N values to insert coords - N x 3 matrix of coords, (not in acpc) vSize - The size of the image volume Copyright (2013-2014), Franco Pestilli, Stanford University, pestillifranco@gmail.com.
0001 function vol3d = feValues2volume(vals,coords,vSize) 0002 % Create a 3D volume of sz and place vals at the coord positions 0003 % 0004 % vol3d = feValues2volume(stat,coords,vSize) 0005 % 0006 % save the vals in the correct locations inside the image volume. 0007 % 0008 % vals - N values to insert 0009 % coords - N x 3 matrix of coords, (not in acpc) 0010 % vSize - The size of the image volume 0011 % 0012 % 0013 % Copyright (2013-2014), Franco Pestilli, Stanford University, pestillifranco@gmail.com. 0014 0015 % Check that we have a value for each coordinate. 0016 if ~( length(vals) == size(coords,1) ) 0017 error('vals (%d) and N coords mis-match (%d)', length(vals),size(coords,1)) 0018 end 0019 0020 % Check that the coordinates are contained inside the volume 0021 if all( vSize(1:3) < max(coords) ) || all(min(coords) < [1 1 1]) 0022 error('Roi coordinates are out of range') 0023 end 0024 0025 % Initialize the volume to nan's 0026 vol3d = nan(vSize); 0027 0028 if (length(vSize) == 3) % This is a statistics that needs to be saved in 3D volume 0029 for iv = 1:length(vals) 0030 vol3d(coords(iv,1),coords(iv,2),coords(iv,3)) = vals(iv); 0031 end 0032 0033 elseif (length(vSize) == 4) % This is signal that needs to be saved in 4D volume 0034 for iv = 1:length(vals) 0035 vol3d(coords(iv,1),coords(iv,2),coords(iv,3),:) = vals(:,iv)'; 0036 end 0037 0038 else 0039 error('[%s] Volume dimensions mismatch',mfilename) 0040 end