Change scanner-space position of the imaging grid to match that of another imaging grid of the same dimensions

Dear Afni experts,

I am trying to align EPIs of a brain that was scanned in 2 different session. The EPIs of the two sessions have the exact same acquisition grid dimensions, and the same position relative to the brain, since they were prescribed with autoalign on a Siemens scanner. So the brain position is well matched in the two image grids, and this is all I want because one of the things I ultimately want is to correct for residual distortions between-session in the phase-encoding direction only. But then, as I want to apply all rigid-body motion corrections and warps in one step with 3dNwarpApply, the fact that the position of the EPIs in scanner space don’t match (the head of the subject was not in exactly the same position relative to the bore) complicates everything (at least for me). After trying a lot, I feel I could accomplish everything easily if only I could fake that the scanner-space position of the second-session grid to be the same as that of the first-session grid. Then it would be just as if both set of EPIs were acquired in a single series of runs repeated in one session.

So the question is: do you have any tool or suggestion of a tricky trick that could change the header information of an EPI such that the scanner-space position of the grid would be the same as the scanner-space position of another EPI that has the same grid dimensions but different position?

Thanks a lot for your help and
Have a very good day!

Sébastien Proulx, MSc, PhD candidate
IPN, McGill

This might be what you want:

copy the coordinate for the center for the first voxel over

3drefit -duporigin session1+orig session2+orig

If the data is oblique, you may want to do this too.

3drefit -atrcopy IJK_TO_DICOM_REAL session1+orig session2+orig

Thanks a lot Daniel, that worked!

Also, just as a note for anybody trying to do similar stuff, I ended up doing a dummy pass of 3dNwarpApply (3dNwarpApply -prefix $out -nwarp ‘IDENT(session1+orig)’ -master session1+orig -source session1+orig -interp NN) on everything before doing anything else. I started doing that sometime ago after encountering problems using 3dNwarpApply to apply all my preprocessing in one steps. 3dNwarpApply seemed to change something in the header that affected slice position, which was problem for me who is not deobliquing and incorporating fsl and freesurfer tools. The dummy pass allowed this change to happen the very beginning and seems to prevent funny things to happen later.


My guess is that your 3dNwarpApply is effectively just removing the obliquity info from the header and keeping everything on the closest cardinal equivalent usually. You can do the same with “3drefit -deoblique”. Note, the data in this case is not transformed; only the header info is removed.

Makes a lot of sense. I’ll keep that in mind. Thanks again for the help Daniel!