EPI to Anat alignment issues


I am having issues with the alignment step of the afniproc.py script for 5 of 25 subjects. I’m attaching the script I use and an example of the misalignment in a subject.

#!/bin/tcsh -f

set subjects = “sub028”
foreach s ( $subjects )
cd $s

afni_proc.py -subj_id $s
-script proc.s -scr_overwrite \ -blocks tshift despike align tlrc volreg blur mask scale regress \ -copy_anat {s}t1.nii \

-tcat_remove_first_trs 2 \

-tcat_remove_last_trs 19 \

    -dsets                                                         \
        ${s}_scene1.nii                                                 \
        ${s}_scene2.nii                                                  \
       -volreg_align_to third                                         \
    -volreg_align_e2a                                              \
    -volreg_tlrc_warp                                             \
    -blur_size 5.0                                                 \
    -blur_in_automask                                              \
    -align_opts_aea -giant_move										\
    -regress_stim_times                                            \
        scene.1d                                                 \
     -regress_stim_labels                                          \
            Scenes     \
   -regress_basis_multi                                            \
           'BLOCK(12)'        \
   -regress_stim_types times                    \
   -regress_apply_mot_types demean                        \
   -mask_segment_anat yes                                         \
   -regress_ROI CSFe WMe                                              \
    -regress_censor_motion 0.3                                     \
    -regress_censor_outliers 0.1                                   \
    -regress_est_blur_errts                                        \
    -regress_run_clustsim no                                       \
    -regress_opts_3dD                                              \
          #-num_glt 4                                              \
          #-gltsym 'SYM: -S +Nature'                \
          #-glt_label 1 Nature-Urban                                   \
          #-gltsym 'SYM: +Urban -Nature'                          \
          #-glt_label 2 Urban-Nature                                          \
-bucket stats.${s}.basic                                             \
-jobs 30                                                            \

-write_3dD_script 3dd.block08 \

-write_3dD_prefix basis.block08 \

    -regress_3dD_stop                                              \
    -regress_reml_exec                                             \

cd …


The 19noAlign.jpg is the output of the above code

Next, I tried different functions for alignment with align_epi_anat.py, specifically:

align_epi_anat.py -epi2anat
-epi pb02.sub002.r01.despike+orig
-anat sub002t1_ns+orig
-epi_base 0 -volreg off -tshift off
-cost lpc -multi_cost lpa lpc+ZZ mi

My alignment isn’t good for any of the cost functions but for this subject al_lpa was the closest. I’ve found too that different subjects have functions that work better but none work perfectly.

Any suggestions on what’s going on or what I should do differently?




It looks like your anat has already been skullstripped; so you should include the following in either/both afni_proc.py and align_epi_anat.py:

-anat_has_skull no

If there is a large rotational difference between the EPI and anat to start with, then going above and beyond -giant_move might be necessary-- try “-ginormous_move” instead (yes, it’s the option’s real name…). I can’t tell if there might be large relative rotation in the attached images, but perhaps try this.

Given the inhomogeneity of the EPI, it might be possible that too much is being stripped away by the auto-masking (done with 3dSkullStrip by default). You could try including:

-epi_strip None

Re. cost functions:
The T1w anat has tissues in order of decreasing brightness: WM, GM, CSF. The EPI looks pretty inhomogeneous. Can you see the ventricles in it clearly? If the pattern of tissue brightness looks more like normal EPI (which is mainly inverted relative to the T1w volume), then using just the “lpc+ZZ” cost function should be your best bet-- the “+ZZ” part adds some stabilizing alignments. But if the inhomogeneity or other EPI features makes the tissue contrast of the EPI look different than normal, “lpa+ZZ” cooould have better alignment.

Separate note on skullstripping and (nonlinear) alignment to standard space: using @SSwarper to accomplish both skullstripping and warping is quite recommended; the results can be fed into afni_proc.py (see the help of that program for the recipe for doing so). It generally gives nice nonlinear alignment to standard space, as well as a well-skullstripped anatomical.


Hello PT,

Thank you for your help with this. I tried align_epi_anat.py with ginormous move, anat_has_skull no, and epi_strip None and still didn’t have luck with good alignment (see image).

align_epi_anat.py -epi2anat
-epi pb02.sub002.r01.despike+orig
-anat sub002t1_ns+orig
-epi_strip None
-anat_has_skull no
-epi_base 0 -volreg off -tshift off
-cost lpc -multi_cost lpa lpc+ZZ mi

The raw scans have better alignment than the processed ones (but still not good).

I’m going to try your other suggestion of SSwarper next and see how that goes. Will keep you posted.



Hmm, weird. But some data is like that…

If you want, I can take a look. I have PM’ed you upload instructions.