misalignment after 3dNwarpCat & 3dNwarpApply with correct intermidate transformations

Hello
When warping an EPI image to MNI space using 3dNwarpCat and 3dNwarpApply, we first computed @SSwarper to obtain the skull-stripped T1-weighted image and the transformations to the MNI space and also performed align_epi_anat.py to align the EPI image to the subject's T1-weighted.

Here are the commands:

@SSwarper                                                  \
    -input  sub-10246_ses-1_run-1_T1w.nii.gz               \
    -base   MNI152_2009_template_SSW.nii.gz                \
    -subid  sub-10246                                      \
    -odir   anat_preproc

align_epi_anat.py                                          \
    -anat            ./anat_preproc/anatSS.sub-10246+orig  \
    -epi             sbref_sub-10246_ns.nii.gz             \
    -epi_base        0                                     \
    -anat2epi                                              \
    -suffix          _al_epi                               \
    -anat_has_skull  no                                    \
    -cost            lpa                                   \
    -giant_move                                            \
    -epi_strip       None                                  \
    -volreg          off                                   \
    -tshift          off                                   \
    -overwrite

Both of these steps resulted in very accurate alignments (from EPI to original T1-w, and also from original T1 to MNI template). However, when concatenating the transformations and applying them with 3NwarpCat and 3dNwarpApply, we observe that the alignment is not so good (e.g. the lateral ventricles do not match between the EPI image in the MNI space and the MNI152 template). Here are the commands:

3dNwarpCat -prefix ./anat_preproc/total_warp_sbref2mni.sub-10246 \
    -warp1 "INV(anatSS.sub-10246_al_epi_mat.aff12.1D)" \
    -warp2 "./anat_preproc/anatQQ.sub-10246.aff12.1D" \
    -warp3 "./anat_preproc/anatQQ.sub-10246_WARP.nii" -overwrite

3dNwarpApply -nwarp "./anat_preproc/total_warp_sbref2mni.sub-10246+tlrc." \
    -source sbref_sub-10246_ns.nii.gz \
    -master MNI152_2009_template_SSW.nii.gz -dxyz 2 -interp wsinc5 \
    -prefix sbref_sub-10246_ns.MNI.nii.gz -overwrite

What could be the reason for this final misalignment?

Thanks very much for your help and feedback
Cesar

Hmm. afni_proc.py concatenates in a slightly different way, so this will make me have to think about what is happening here (horror!) after only one cup of coffee. Ergo, caveat emptor, but I think you should reverse the order of concatenation, which I have done here:

3dNwarpCat -prefix ./anat_preproc/total_warp_sbref2mni.sub-10246 \
   -warp3 "INV(anatSS.sub-10246_al_epi_mat.aff12.1D)" \
   -warp2 "./anat_preproc/anatQQ.sub-10246.aff12.1D" \
   -warp1 "./anat_preproc/anatQQ.sub-10246_WARP.nii" -overwrite

Also, just to check, what is the output of:

3dinfo -is_oblique sub-10246_ses-1_run-1_T1w.nii.gz
3dinfo -is_oblique sbref_sub-10246_ns.nii.gz 

?

--pt

Hi Paul,

You are genious even with only one cup of coffee in the morning!!
It worked perfectly.... which means that my understanding of the sequence of transformations in 3dNwarpCat is not very good.

Btw, both datasets are oblique.. ;-)

Thanks a lot
Cesar

Ps. I own you another cup of coffee!! or RS match :slight_smile:

Hi, César-

Ha, you are too kind. But I'll definitely be happy to schedule the coffee+RS match, looking at my calendar now...

Re. obliquity: perfectly fine to leave the EPI oblique and let the processing (typically afni_proc.py, which would do these pieces of things you asked about here, as well) deal with that. However, we do typically recommend deobliquing the anatomical before processing, esp. if you are using FreeSurfer, because it will apply the obliquity during processing. We have a new tool called adjunct_deob_around_origin to deoblique the anatomical, with this preferred combination of properties:

  • removing obliquity
  • preserving the coordinate origin (x,y,z)=(0,0,0)
  • not blurring/resampling the data at all

At its simplest (which would be 99% of cases) would just use it like:

adjunct_deob_around_origin                       \
    -input   sub-001_T1w.nii.gz                  \
    -prefix  sub-001_T1w_DEOB.nii.gz

Re. transformations: One of the keys is not to think about mapping the data from the EPI to the template, but instead think about the template pulling data from the EPI. Then think about ordering the transforms by working backwards from the template. So, we normally think about aligning EPI->anatomical, then affine alignment of anatomical->template and then nonlinear refinement of that to template (the *_WARP.nii dataset). In such a case, then the ordering would be:

  • warp1 is the nonlinear refinement warp
  • warp2 is the affine anatomical->template
  • warp3 is the affine EPI->anatomical, which here---as it usually is---is the INV(anatomical->EPI).

That is the general rule for ordering---think backwards! And maybe that part is easier before I have more coffee...

--pt

Hi Paul,

Thanks for the wise advice. I will use adjunct_deob_around_origin before running freesurfer.

César