Hi everybody,
I'm writing a script to automatically identify a certain type of artifact in DW images.
Basically, what the script does is taking a 4D volume for each subject comprising the b0 and the (32) b1000 images, going through all the slice and identifying the artifacts.
Once these processes performed for all volumes in the 4D volume, the script creates a new 4D matrix using only the volumes that are artifact-free, strips the bvec and bvals files of the direction in which the artifacts were present.
After all this, I would like to write again the images as a single 4D volume, comprising only the directions that are artifact free.
Now the problem is that it seems that a 4D equivalent of spm_write_vol does not exist, or at least I am not able to find it.
I took a look in the list archive and I found out an old conversation (2008) reporting this function:
%% FUNCTION FOR CREATING 4-D NIFTI FILES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% MODIFIED FROM spm_config_3Dto4D.m (20 june 2007)
%
% Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
%
% John Ashburner
% $Id: spm_config_3Dto4D.m 245 2005-09-27 14:16:41Z guillaume $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function nii_3Dto4D(files,save_name)
V = spm_vol(strvcat(files{:}));
ind = cat(1,V.n);
N = cat(1,V.private);
mx = -Inf;
mn = Inf;
for i=1:numel(V),
dat = V(i).private.dat(:,:,:,ind(i,1),ind(i,2));
dat = dat(finite(dat));
mx = max(mx,max(dat(:)));
mn = min(mn,min(dat(:)));
end
sf = max(mx,-mn)/32767;
ni = nifti;
ni.dat = file_array(sprintf('%s',save_name),[V(1).dim, numel(V)],'INT16-BE',0,sf,0);
ni.mat = N(1).mat;
ni.mat0 = N(1).mat;
ni.descrip = '4D image';
create(ni);
for i=1:size(ni.dat,4),
ni.dat(:,:,:,i) = N(i).dat(:,:,:,ind(i,1),ind(i,2));
spm_get_space([ni.dat.fname ',' num2str(i)], V(i).mat);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Some function called in the script does not exist no more (like finite, that is now isfinite) but even when I updated the script, the function crash saying
??? Error using ==> nifti.subsasgn>assigndat at 367
Unknown filename extension ().
Error in ==> nifti.subsasgn>fun at 76
obj = assigndat(obj,val);
Error in ==> nifti.subsasgn at 20
obji = fun(obji,subs,val);
Error in ==> nii_3Dto4D at 31
ni.dat =
file_array(sprintf('%s',save_name),[V(1).dim,numel(V)],'INT16-BE',0,sf,0);
So my questions are:
1)does it exist a 4D equivalent of spm_write_vol ?
2)if not, how I can transform a bunch of 3D volume in one 4D volume using the command line ?
Thank in advance for any help and tips
F.
|