how to change orientation infomation in head file but keep the oritation of image


I’m frustrated the 3drefit function for a while:
I have a field map data (I extract magnitude(mag) image and the mag image 3dinfo showed orientation is SAR) and a CEST data (3dinfo showed orientation LSP) from rat brain and try to run the field map correction for the CEST image.
I resample them to 4x4x4 with
3dresample -dxyz 4 4 4 -prefix mag_res_brain444.nii -inset mag_res_brain.nii.gz
3dresample -dxyz 4 4 4 -prefix CEST_res_brain444.nii -inset CEST_res_brain.nii.gz
then the orientation of mag_res_brain444.nii from 3dinfo is still SAR (fig mag_CEST_info_1, whole brain image,mag_3dinfo)
and the orientation of CEST_res_brain444.nii from 3dinfo is still LSP (fig mag_CEST_info_1, 5 slices coronal image)
and the AFNI view of the two images show same orientation (fig mag_CEST_info_1 ) like raw images before 3dresample.

I used 3drefit to change the head file of mag_res_brain444.nii to LSP for CEST image is LSP orientation then align it to CEST image, but it failed.
3drefit -deoblique -epan -orient LSP -xdel 4 -ydel 4 -zdel 4 mag_res_brain444_1+orig
the mag_res_brain444_1+orig show [-orient LSP] but AFNI view show the orientation totally changed (fig mag_3drefit).
so, 1. why 3dresample made image to 4x4x4 but AFNI view of CEST_res_brain444.nii still show 20x20x4 like before 3dresample? how to fix it?
2. Why the AFNI view show the image orientation was changed if 3drefit only change the orientation information in head file? how to fix it?
3. Is this a right strategy to make 3dinfo and AFNI view consistent in mag and CEST then align the mag image to CEST?
Thanks a lot,

Hi, Tracy-

Preliminary note:

  • 3dresample is generally to use when the data and their header information are both correct. This program can then be used to change the data+header together.
  • 3drefit is generally to use when something in the header information is wrong, and you want to change just the header (fixing a value), to match with the data.

Can you please list what you would like to change, and whether you view it as currently correct or wrong in your current data?

Also, is your data oblique? What is the output of:

3dinfo -is_oblique DATASET

for each original dataset (before resampling or refitting)?

Note that “3dresample -dxyz A B C …” will just change the voxel size, not the orientation.

Re. the 2nd command: I don’t see an option “-epan” in 3dreft’s help, so I’m not sure what that is.


The “epan” is the “echo planar” dataset type in the -‘type’ option. It’s rarely used except for setting -anat type in order for the dataset chooser in afni to show it first.

Hi, Ptaylor,
Thanks for your reply!

I ran the script what your suggested and got the followed result:
3dinfo -is_oblique mag_res_brain.nii.gz
3dinfo -is_oblique CEST_res_brain.nii.gz

I tried other way to rotate the mag to match the CEST orientation, then align mag to CEST with 3dresample -master CEST.nii -prefix mag_to_CEST.nii -inset mag.nii, is this right one to align mag to CEST image?


Thanks for clarification.


The datasets not having obliquity (the output of those 3dinfo commands shows that) simplifies things a bit.

Can you please list what you would like to change, and whether you view it as currently correct or wrong in your current data?


Hi, ptaylor,
The mag data and CEST data both look “correct” and only 3dinfo showed different orientation. I used fslswapdim to make both of them have same orientation (RIP) in AFNI view and 3dinfo. I tried plug-nodge to manually rotate CEST to align it to mag image,but failed. Is there other better way to align CEST (part of brain) to mag image (whole brain)?


If the data are in the same spot, and you only want the data orientations to match, then you can run 3dresample.

You could change one dset orientation to match that of the other, or change both to something nice like RAI (I am using made-up input and prefix file names here…):

3dresample -prefix MAG_RAI.nii.gz -orient RAI -input DSET_MAG
3dresample -prefix CEST_RAI.nii.gz -orient RAI -input DSET_CEST

After this, the datasets should appear in the same locations in the GUI (that is, nothing with coordinates will have changed), but now the orientation of the data stored on disk should match (RAI in both cases); you can verify this with:

3dinfo -orient -prefix MAG_RAI.nii.gz CEST_RAI.nii.gz

To perform alignment—yes, you can do that with our alignment programs. Many people have partial data to align to whole brain, and it can be done. There are details that matter though: do the two dsets have similar or opposite tissue contrast (–> determines what cost function to use)? Do they start off close-to-well-aligned or not (—> getting to a good starting point is nice, as there is less chance of a dset wandering off into space accidentally)?

For the second point here, what does the output image:

@djunct_overlap_check -ulay MAG_RAI.nii.gz -olay CEST_RAI.nii.gz -prefix image_mag_cest

look like? (It will show how well the dsets overlap to start.)