using to3d with .nii data


I’m totally new with AFNI and working on an old dataset that has been converted to .nii format by SPM.
I thought AFNI could read .nii flies so I tried to3d directly to the structural data but it failed to output brik and head files.

to3d -spgr -session …/ -prefix RSA_S1_t1 20130912_145129t1mpragetranssrs002a1001.nii
++ to3d: AFNI version=AFNI_18.0.25 (Mar 7 2018) [64-bit]
++ Authored by: RW Cox
++ It is best to use to3d via the Dimon program.
++ Counting images: total=192 2D slices
++ Each 2D slice is 448 X 512 pixels
++ Image data type = short
++ Reading images: …
*+ WARNING: *** ILLEGAL INPUTS (cannot save) ***

Axes orientations are not consistent!

I tried with epi data too and got similar output. Am I doing something wrong? Should I convert these .nii files to .dcm first?

Thank you in advance!


I guess the place to start is “what do you want to to to the data set”? to3d is for converting DICOMs to a NIFTI (or BRIK/HEAD) file. So, it doesn’t sound like you would need that in this case. Also, AFNI reads/writes/calculates with NIFTI files just fine, so you should be able to use this file directly within AFNI, likely (unless something is reaaaaallly wrong with it).

To see properties of the data set :


To change information in the data’s header that is wrong, you can use 3drefit. To adjust header info that is correct and its matching data, you can use 3dresample.

To find out more about AFNI functions, here might be a good place to start:


Thank you very much for your reply!
One more naive question:
I want to convert .nii files for each epi run into one single AFNI format dataset with time series info so I can do preprocessing.
How can I achieve that or do I even need to do that for preprocessing?

You can process multiple runs of EPI data without concatenating them to start (and probably you shouldn’t concatenate them to start).

In the AFNI Bootcamp demo data set, there is an example of this; you can get the Bootcamp data as described under the “Boot Up” step here:
and then in the AFNI_data6/FT_analysis/ directory there is a README.txt file; example data in teh FT/ subdirectory, and processing command examples with, such as “s05.ap.uber” as a starting point (for task-based analysis).

Please let us know if you have more questions about that.


Sorry. I mean I have multiple .nii files for each epi run (one for each volume) and I want to concatenate them into single dataset for each run.

Oh, I see-- please check out 3dTcat for that.