AFNI version info (afni -ver):
which afni : /home/rodtif/abin_25/afni
afni version : Precompiled binary linux_ubuntu_24_64: Jul 4 2025
: AFNI_25.2.03 'Gordian I'
AFNI_version.txt : AFNI_25.2.03, linux_ubuntu_24_64, Jul 04 2025, official
which python : /home/rodtif/miniconda3/bin/python
python version : 3.13.9
which R : /home/rodtif/miniconda3/bin/R
R version : R version 4.4.1 (x86_64-conda-linux-gnu)
# Step 1: Run sswarper2 first (skullstripping + nonlinear alignment)
cd /media/rodtif/Lozano_12TB/TIFFANY/AFNI_TWH
sswarper2 \
-input sub-001/ses-01/anat/sub-001_ses-01_T1w.nii.gz \
-base /home/rodtif/abin_25/MNI152_2009_template_SSW.nii.gz \
-subid sub-001 \
-odir sub-001/sswarper_output
# Step 2: Run afni_proc.py using sswarper2 results
afni_proc.py \
-subj_id sub-001 \
-copy_anat sub-001/sswarper_output/anatSS.sub-001.nii \
-anat_has_skull no \
-dsets sub-001/ses-01/func/sub-001_ses-01_task-rest_bold.nii.gz \
-blocks tshift align tlrc volreg blur mask scale regress \
-radial_correlate_blocks tcat volreg regress \
-tcat_remove_first_trs 1 \
-align_unifize_epi local \
-align_opts_aea -cost lpc+ZZ -giant_move -check_flip \
-tlrc_base /home/rodtif/abin_25/MNI152_2009_template_SSW.nii.gz \
-tlrc_NL_warp \
-tlrc_NL_warped_dsets sub-001/sswarper_output/anatQQ.sub-001.nii \
sub-001/sswarper_output/anatQQ.sub-001.aff12.1D \
sub-001/sswarper_output/anatQQ.sub-001_WARP.nii \
-volreg_align_to MIN_OUTLIER \
-volreg_align_e2a \
-volreg_tlrc_warp \
-volreg_compute_tsnr yes \
-mask_epi_anat yes \
-blur_size 6 \
-regress_motion_per_run \
-regress_censor_motion 0.3 \
-regress_censor_outliers 0.05 \
-regress_apply_mot_types demean deriv \
-regress_est_blur_epits \
-regress_est_blur_errts \
-regress_run_clustsim no \
-html_review_style pythonic \
-execute
Question:
Hi!
I am preprocessing resting-state fMRI data and only have a BOLD sequence and a T1 (no reverse-phase encoding or fieldmap). I ran sswarper2 followed by afni_proc.py using the command above (AFNI 25.2.03).
For some subjects, I see noticeable distortion in the ve2a (EPI-to-anat) section of the HTML review
My primary regions of interest are deep brain structures (e.g., STN, thalamus), which are generally less affected by susceptibility distortion than frontal or temporal regions. Given this, I have two related questions:
- Is it reasonable to proceed without distortion correction for deep-structure analyses, or would residual distortion meaningfully affect registration accuracy there?
- If correction is warranted, what is the recommended approach within AFNI when only a T1 is available? I've read about using
3dQwarp to nonlinearly warp the EPI to the anatomical (constrained to the phase-encoding direction), but I'm not sure if this is best practice or whether there are pitfalls to avoid.
Any guidance is much appreciated. Thank you!
Kind regards,
Tiffany
Hi, Tiffany-
Hm, interesting. Looking at the overlap images of the EPI on the anatomical dsets, it looks like the EPI actually isn't that distorted there to start with.
I think what is happening is something different than distortion in the original EPI image. I'll note that standard T1w tissue contrasts have the white matter as the brightest tissue, then GM, then CSF. Also, standard EPI sequences have opposite tissue contrast: ventricles are dark, the WM is medium bright, and the GM is brightest. That is, EPI-anatomical dsets have opposite tissue contrasts, and the cost function to align them (lpc+ZZ) is constructed to handle that.
Here, it actually looks like your EPI tissue contrast is different than what we normally see. Here, the ventricles are actually dark---in standard EPI sequences, the ventricles are bright. The cost function used to do EPI-anatomical alignment kind of assumes that the EPI and T1w contrasts are opposite. Out of curiosity, is that something that is particularly desired or specific to this sequence?
I think for this EPI data, you might want to choose a different cost function for EPI-anatomical alignment. You could try "lpa" perhaps (and as a third choice, you could try "nmi"). On a separate note, since your EPI-anatomical alignment is quite good to start wtih, let's not use -giant_move, but instead use -large_move, to avoid an unnecessary center of mass pre-alignment.
So, how about adjusting this option to be like:
-align_opts_aea -cost lpa -large_move -check_flip \
and please let us know how that looks?
-pt
Hi Paul,
Thank you for your quick response! I applied the changes you suggested and the EPI-to-anat alignment looks much better.
One thing worth noting: -large_move was not recognized by my version of align_epi_anat.py (AFNI_25.2.03, Jul 2025), throwing the error unknown arg #16 (-large_move). I updated to AFNI_26.1.02 and it worked as expected.
Regarding the EPI tissue contrast, I will attach a screenshot of the raw fMRI data. The ventricles are indeed bright as expected. This is a clinical dataset so I had limited control over acquisition parameters, but the JSON confirms standard BOLD parameters (TE=30ms, TR=2.2s, flip angle=85° on a GE Signa HDxt at 3T).
I've also attached the new ve2a screenshots for comparison.
For reference, here is the code I ran:
afni_proc.py \
-subj_id sub-001_lpa \
-out_dir sub-001.results_lpa \
-copy_anat sub-001/sswarper_output/anatSS.sub-001.nii \
-anat_has_skull no \
-dsets sub-001/ses-01/func/sub-001_ses-01_task-rest_bold.nii.gz \
-blocks tshift align tlrc volreg blur mask scale regress \
-radial_correlate_blocks tcat volreg regress \
-tcat_remove_first_trs 1 \
-align_unifize_epi local \
-align_opts_aea -cost lpa -large_move -check_flip \
-tlrc_base /home/rodtif/abin_25/MNI152_2009_template_SSW.nii.gz \
-tlrc_NL_warp \
-tlrc_NL_warped_dsets sub-001/sswarper_output/anatQQ.sub-001.nii \
sub-001/sswarper_output/anatQQ.sub-001.aff12.1D \
sub-001/sswarper_output/anatQQ.sub-001_WARP.nii \
-volreg_align_to MIN_OUTLIER \
-volreg_align_e2a \
-volreg_tlrc_warp \
-volreg_compute_tsnr yes \
-mask_epi_anat yes \
-blur_size 6 \
-regress_motion_per_run \
-regress_censor_motion 0.3 \
-regress_censor_outliers 0.05 \
-regress_apply_mot_types demean deriv \
-regress_est_blur_epits \
-regress_est_blur_errts \
-regress_run_clustsim no \
-html_review_style pythonic \
-execute
Kind regards,
Tiffany
Hi, Tiffany-
Ah, right, thanks for catching that about the AFNI version numbers and -large_move being available. It is indeed a slightly newer option.
That is interesting about the ventricle brightness. I guess what I thought was ventricles in the original image was some dropout happening, and (mistakenly) appearing to me at that angle to be ventricles. Thanks for checking with that other image; I guess the other vorig EPI image would show that, too.
Indeed, the alignment is better and much less distorted now, but I am not 100% convinced that the sulci and gyri are lining up, which is the key thing desired. It is a little hard to tell because of the similar tissue brightness of GM and WM in the EPI, but I still think it could be better. If you tried using "nmi", I wonder if it would look better? So, adjusting the EPI-anatomical alignment to be:
-align_opts_aea -cost nmi -large_move -check_flip \
Thanks,
pt
Hi Paul,
Thank you for the feedback, it has made navigating ANFI a great experience.
I ran the same command, only changing the -align_opts_aea component as you suggested above. I have attached a screenshot of he new EPI-anatomical alignment. I'm not quite sure which of the two (lpa vs nmi) is better. What do you think?
Worth noting is that with our clinical scans, we expect that the output quality may be slightly inferior to that of research scans.
Thank you,
Tiffany
I will reply here, having taken a look at some of the data.
In this case, there was a pre-steady state volume at the start of the EPI time series which we could leverage for its notably higher tissue contrast. This helped EPI-anatomical alignment. For motion estimation, we still used the MIN_OUTLIER volume.
So, the adapted AP command was:
afni_proc.py \
-subj_id ${subj} \
-out_dir ${sdir_ap}/${subjid}.results \
-copy_anat ${dset_anat} \
-anat_has_skull yes \
-dsets ${dset_epi} \
-blocks tshift align tlrc volreg blur mask scale \
regress \
-radial_correlate_blocks tcat volreg regress \
-tcat_remove_first_trs 1 \
-align_unifize_epi local \
-align_epi_ext_dset ${dset_epi}"[0]" \
-align_opts_aea -cost lpc+ZZ \
-large_move \
-check_flip \
-tlrc_base MNI152_2009_template_SSW.nii.gz \
-tlrc_NL_warp \
-tlrc_NL_warped_dsets sub-001/sswarper_output/anatQQ.sub-001.nii \
sub-001/sswarper_output/anatQQ.sub-001.aff12.1D \
sub-001/sswarper_output/anatQQ.sub-001_WARP.nii \
-volreg_align_to MIN_OUTLIER \
-volreg_align_e2a \
-volreg_tlrc_warp \
-volreg_compute_tsnr yes \
-mask_epi_anat yes \
-blur_size 6 \
-regress_motion_per_run \
-regress_censor_motion 0.3 \
-regress_censor_outliers 0.05 \
-regress_apply_mot_types demean deriv \
-regress_est_blur_epits \
-regress_est_blur_errts \
-regress_run_clustsim no \
-html_review_style pythonic
... where adding this opt: -align_epi_ext_dset ${dset_epi}"[0]" is what allows the pre-steady-stead [0]th volume from the EPI time series to be used for EPI-anatomical alignment in particular. That volume is still removed from subsequent time series analysis/processing/regression, via -tcat_remove_first_trs 1. For the EPI-anatomical cost function, lpc+ZZ worked well again, for this chosen alignment volume.
--pt