Dear Federico,
you can use spm_select from the command line, see e.g.:
>> spm_select('ExtFPList',fullfile(spm('Dir'),'canonical'),'.*T1\.nii$')
In SPM8/SPM12, the function that creates a 4D file given a series of 3D
files is called spm_file_merge.m.
Best regards,
Guillaume.
On 28/10/14 13:54, federico nemmi wrote:
> Hi,
>
> you're right.
>
> The list of filenames is selcted in the script using dir and then
> listing the name, so that it hasn't the structure used by spm_select.
> However, I would like to keep everything in the command line.
> I (think I have) resolved my problem using save_avw.
> Thanks a lot anyway
>
> F.
>
> 2014-10-28 14:22 GMT+01:00 John Ashburner <[log in to unmask]
> <mailto:[log in to unmask]>>:
>
> How did you select filenames? Did you use spm_select(Inf,'image')
> ? Check to see if the filenames have a ",1" at the end of them. If
> they have, then this is likely to cause problems.
>
> Best regards,
> -John
>
>
> On 28 October 2014 12:32, Federico Nemmi <[log in to unmask]
> <mailto:[log in to unmask]>> wrote:
>
> 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.
>
>
>
>
>
> --
> Federico Nemmi, PhD
>
--
Guillaume Flandin, PhD
Wellcome Trust Centre for Neuroimaging
University College London
12 Queen Square
London WC1N 3BG
|