output 4D

We’re using to perform coregistration on resting state MRI data. The script does work but it doesn’t give us the desired output. As input we’re giving a .nii.gz anatomical file and a functional .nii.gz file with about 98 volumes. gives us a 1D file as output, which makes sense when looking at the docs, but we’re wondering if it’s possible to receive a 4D file with more than one volume. For further preprocessing steps it wouldn’t make any sense to continu on with a 1D file.

Is there an option in or are there different programs with Afni?

Thanks in advance.

Can you please copy+paste the full command that you are typing/using?

Note that often with FMRI processing, would be run within an command. While it can be useful to test EPI-anatomical alignment options separately, putting those options for to use is nice because then that alignment step gets properly concatenated within the full processing stream for each subject.

Also, it would be nice to see the version of AFNI you are using.


Hi there,

Thanks for your response.

The command we’re running is: -anat2epi -anat " + functional_dir + " -save_skullstrip -suffix "
“al_junk -epi " + input_name_coregistration + " -epi_base 0 -epi_strip 3dAutomask -giant_move -volreg off -tshift off”

Where the functional_dir is a .nii.gz with more than one volume and the input_name_coregistration is a anatomical.nii.gz with only 1 volume.

This is in Python with string concatenation, the input files are saved in a variable because we’re running it in a pipeline.

I am using Afni version AFNI_21.0.12 ‘Titus’ on MacOS Big Sur.


Hi, Eric-

Are there some things missing from that command? I don’t see an “-epi …” input, for example, and there are an odd number of double-quotes.

As an example, this is an example of generated by from the Bootcamp example in “AFNI_data6/FT/FT_analysis/”:

# ================================= align ==================================
# for e2a: compute anat alignment transformation to EPI registration base
# (new anat will be intermediate, stripped, FT_anat_ns+orig) -anat2epi -anat FT_anat+orig   \
       -save_skullstrip -suffix _al_junk         \
       -epi vr_base_min_outlier+orig -epi_base 0 \
       -epi_strip 3dAutomask                     \
       -cost lpc+ZZ -giant_move -check_flip      \
       -volreg off -tshift off

… though perhaps you have based your own command on this?

That being, said, you mention that a “1D file” is output— I had interpreted this as a “1D text file” of alignment parameters, but perhaps you mean a “3D volume” gets output, which is should with the specified suffix, because you juxtapose it with getting a 4D volumetric output? Could you please list the outputs you do get?

Note that EPI-anatomical alignment is a 3D volume to 3D volume procedure: one EPI volume gets picked out. Typically the “whole time series being aligned” procedure comes from 3dvolreg, aligning each EPI volume to a particular EPI volume (called the “base EPI” volume, chosen using a nice minimum-outlier criterion within

The 3dvolreg command is run separately, as is anatomical-to-template alignment, and all the alignment procedure outputs are concatenated before applying them as a single transform to the original EPI dset. A lot more about this procedure and these considerations are described in the AFNI Bootcamp videos on alignment:

Note that handles a lot of this concatenation/etc. under the hood, and it is a really useful tool for designing a processing pipeline.

Please let me know if I have misunderstood the question here and waffled on needlessly (which is a distinct possibility…).


Hi there,

Thanks again for your response.

I did copy and paste the command from my python script incorrectly, that’s why the amount of double-quotes is odd.
We’re using the -epi, I pasted the entire line of code from the Python script down below.

os.system(" -anat2epi -anat " + functional_dir + " -save_skullstrip -suffix "
“al_junk -epi " + input_name_coregistration + " -epi_base 0 -epi_strip 3dAutomask -giant_move -volreg off -tshift off”)

I am using os.system to run commands on the command line via Python. As I said in the message before the functional_dir was the .nii.gz with more than one volume. So they are 3D images, with about 10 seconds between them. When I open this file in for example, MRIcron, it will ask me which volume I would like to see.

The input_name_coregistration is the 3D anatomical image, with only one volume.

After running the command the output gives me, as you said, a 3D image with only one volume. However, the size of this file still is about the same size as the input file with more than one volume. I would like to have an output file with more than one volume but each volume must be coregistred to this one anatomical dataset.

I am very new to Afni, so excuse me if I’m misinterpreting some basic usages of Afni.


The program should give you an output 3D/4D dataset and 1D files for the affine transformations too. In this case, you are asking for the output to be the aligned anatomical dataset, so you should find that single volume dataset called something like “anatal_junk+orig.HEAD/BRIK” in the output. The AFNI format is used for the output instead of NIFTI. You can convert that to NIFTI with 3dcopy. Note the anatomical to EPI transformation is the default and the first one computed. If you really want the reverse, then use “-epi2anat” instead of “-anat2epi”.

Yeah, my output is something like anatal_junk+orig.HEAD/BRIK. And this is a 3D file, it only contains one image. I would like to have a 4D file with the same amount of volumes as the input functional .nii.gz (98 volumes). Should I try to run this coregistration for each volume separately or can I somehow run it on each one of them with only 1 run and also get an output with 98 volumes?

I found out what I did wrong, I accidentally gave the wrong input. After that I only had to add -epi2anat instead of -anat2epi. Thanks for the help!