Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

03 Preprocessing & afni_proc.py

Authors
Affiliations
Georgia Center for Developmental Science
University of Georgia

Preprocessing

Preprocessing includes a lot of steps to reduce the variability of the data. Our final goal is to increase signal-to-noise ratio (SNR) because when you collect data, noise will come up from both the participants and the MRI device.

General preprocessing including reconstruction (convert 2D images to 3D or 4D), slice-timing correction, motion correction, co-registration of structural and functional images, normalization to standard space, and spatial smoothing, but what steps need to be done depends on your experiments and data.

Workflow

workflow1 workflow2 workflow3

Noise from Participants

Remove TR

fMRI measures brain activity indirectly by tracking changes in blood flow, which are linked to neuronal activity through the blood-oxygen-level-dependent (BOLD) signal. When a stimulus is presented, there is often a delay between the neural response and the corresponding BOLD signal due to the time it takes for blood flow to change in response to neural activity, meaning that it takes some time for neural activity to transition from baseline to an ‘active’ state. Additionally, at the beginning of an fMRI scanning session, the MRI signal can be unstable as the magnetic fields and scanner components reach equilibrium. This period is known as the “transient phase.”

To ensure that the data analyzed reflect a stable baseline and accurate neural activity, researchers often discard the initial few time points (TRs, or time repetitions) of the fMRI time series. The exact number of TRs discarded can vary (often around 0 to 10) depending on the study design and the stability of the scanner.

Motion Correction (Realign)

Temporal Filtering and Physiological Noise

Noise from MRI Scanner

Slice-timing correction (temporal interpolation)

Co-registration

Segmentation

Normalization

Spatial Smoothing

The image becomes blurry (reduced spatial resolution). The use of a Gaussian spatial filter efficiently distributes the intensity of each voxel across adjacent voxels.

Figure 1:The image becomes blurry (reduced spatial resolution). The use of a Gaussian spatial filter efficiently distributes the intensity of each voxel across adjacent voxels.

Mask

Scaling

Distortion Correction

Figure: Hutton C, Bork A, Josephs O, Deichmann R, Ashburner J, Turner R. Image distortion correction in fMRI: A quantitative evaluation. Neuroimage. 2002 May;16(1):217-40. doi: 10.1006/nimg.2001.1054. PMID: 11969330.

Figure 2:Figure: Hutton C, Bork A, Josephs O, Deichmann R, Ashburner J, Turner R. Image distortion correction in fMRI: A quantitative evaluation. Neuroimage. 2002 May;16(1):217-40. doi: 10.1006/nimg.2001.1054. PMID: 11969330.

Script

This section is still in development.

See AFNI’s notes of script here: https://afni.nimh.nih.gov/pub/dist/doc/htmldoc/programs/alpha/afni_proc.py_sphx.html#sample-analysis-script

afni_proc.py                                                      \
    -subj_id                  FT.e6b                              \   
    # Set the subject ID to FT.e6b.
    -copy_anat                Qwarp/anat_warped/anatSS.FT.nii     \   
    # Copy anatomical data using the specified anatomical image from the Qwarp directory.
    -anat_has_skull           no                                  \   
    # Specify that the anatomical image does not include the skull (i.e., the skull has been removed).
    -anat_follower            anat_w_skull anat FT/FT_anat+orig   \   
    # Specify the following anatomical files, including the one with the skull and the original anatomical image.
    -dsets                    FT/FT_epi_r?+orig.HEAD              \   
    # Specify the functional MRI dataset, using the EPI data from the FT directory.
    -blocks                   tshift align tlrc volreg mask blur  \   
    # Define the sequence of preprocessing steps
    # time shifting (tshift), alignment (align), spatial normalization (tlrc), volume registration (volreg), masking (mask), and smoothing (blur).
                              scale regress                      \   
                              # Also include scaling (scale) and regression analysis (regress).
    -radial_correlate_blocks  tcat volreg                         \   
    # Perform radial correlation correction on the time shift (tcat) and volume registration (volreg) blocks.
    -tcat_remove_first_trs    2                                   \   
    # Remove the first two time points (TRs) from each functional dataset.
    -align_unifize_epi        local                               \   
    # Apply local uniformization (local) to the EPI data during alignment.
    -align_opts_aea           -cost lpc+ZZ                        \   
    # Alignment options: use the local phase consistency cost function (lpc+ZZ).
                              -giant_move                        \   
                              # Allow large movements (giant_move) during alignment.
                              -check_flip                        \   
                              # Check for potential flip issues during alignment.
    -tlrc_base                MNI152_2009_template_SSW.nii.gz     \   
    # Use the MNI152 2009 template as the reference for spatial normalization.
    -tlrc_NL_warp                                                 \   
    # Enable nonlinear normalization to the MNI template.
    -tlrc_NL_warped_dsets     Qwarp/anat_warped/anatQQ.FT.nii     \   
    # Specify the anatomical dataset after nonlinear normalization.
                              Qwarp/anat_warped/anatQQ.FT.aff12.1D   
                              # Specify the affine transformation matrix for nonlinear normalization.
                              Qwarp/anat_warped/anatQQ.FT_WARP.nii   
                              # Specify the warp file for nonlinear normalization.
    -volreg_align_to          MIN_OUTLIER                         \   
    # Align to the time point with the minimum outlier during volume registration.
    -volreg_align_e2a                                             \   
    # Align the EPI data to the anatomical data during volume registration.
    -volreg_tlrc_warp                                             \   
    # Apply the spatial normalization transformation during volume registration.
    -volreg_compute_tsnr      yes                                 \   
    # Compute the temporal signal-to-noise ratio (TSNR).
    -mask_epi_anat            yes                                 \   
    # Use the anatomical data to create a mask for the functional data.
    -blur_size                4.0                                 \   
    # Apply spatial smoothing with a 4.0 mm full-width half-maximum (FWHM).
    
    # Generate the HTML review pages to do quality control.
    -html_review_style        pythonic                            \   
   
    # Execute the entire analysis pipeline.
    -execute                                                      

Resource (Highly Suggested)

Short introduction:

https://youtu.be/xLWES956JJE?si=kI9iahR1Oz1aiVcb

But I will suggest you to watch these two videos:

https://youtu.be/vcDm_fdNews?si=PO28PAIwITSpNvLe

https://youtu.be/fraTFUoKV6c?si=1tQ2AaH2nFTfM1oV

Reference

Strother, S. C. (2006). Evaluating fMRI preprocessing pipelines. IEEE Engineering in Medicine and Biology Magazine25(2), 27-41.

H. A. Jaber, H. K. Aljobouri, İ. Çankaya, O. M. Koçak and O. Algin, “Preparing fMRI Data for Postprocessing: Conversion Modalities, Preprocessing Pipeline, and Parametric and Nonparametric Approaches,” in IEEE Access, vol. 7, pp. 122864-122877, 2019, doi: 10.1109/ACCESS.2019.2937482. keywords: {Functional magnetic resonance imaging;Tools;Pipelines;Statistical analysis;DICOM;Smoothing methods;Data analysis;Analyze data (img/hdr);DICOM;fMRI;NIFTI;parametric and nonparametric approaches},

https://s.mriquestions.com/data-pre-processing.html

https://afni.nimh.nih.gov/pub/dist/doc/htmldoc/programs/alpha/afni_proc.py_sphx.html#ahelp-afni-proc-py

https://andysbrainbook.readthedocs.io/en/latest/AFNI/AFNI_Short_Course/AFNI_Preprocessing/AFNI_Intermezzo_Uber_Subject.html

https://cloud.wikis.utexas.edu/wiki/spaces/~mvf327/pages/70001952/Preprocessing+with+AFNI

https://en.wikibooks.org/wiki/Neuroimaging_Data_Processing/Processing/Steps

https://cbmm.mit.edu/afni

Footnotes
  1. Huettel, S. A., Song, A. W., & Mccarthy, G. (2004). Functional magnetic resonance imaging. Sinauer Associates, Publishers.

  2. Richard C. Reynolds, Daniel R. Glen, Gang Chen, Ziad S. Saad, Robert W. Cox, Paul A. Taylor; Processing, evaluating, and understanding FMRI data with afni_proc.py. Imaging Neuroscience 2024; 2 1–52. doi: Reynolds et al. (2024)

References
  1. Greene, D. J., Koller, J. M., Hampton, J. M., Wesevich, V., Van, A. N., Nguyen, A. L., Hoyt, C. R., McIntyre, L., Earl, E. A., Klein, R. L., Shimony, J. S., Petersen, S. E., Schlaggar, B. L., Fair, D. A., & Dosenbach, N. U. F. (2018). Behavioral interventions for reducing head motion during MRI scans in children. NeuroImage, 171, 234–245. 10.1016/j.neuroimage.2018.01.023
  2. Jones, T. B., Bandettini, P. A., & Birn, R. M. (2008). Integration of motion correction and physiological noise regression in fMRI. NeuroImage, 42(2), 582–590. 10.1016/j.neuroimage.2008.05.019
  3. Zaitsev, M., Akin, B., LeVan, P., & Knowles, B. R. (2017). Prospective motion correction in functional MRI. NeuroImage, 154, 33–42. 10.1016/j.neuroimage.2016.11.014
  4. Hutton, C., Josephs, O., Stadler, J., Featherstone, E., Reid, A., Speck, O., Bernarding, J., & Weiskopf, N. (2011). The impact of physiological noise correction on fMRI at 7 T. NeuroImage, 57(1), 101–112. 10.1016/j.neuroimage.2011.04.018
  5. Kopel, R., Sladky, R., Laub, P., Koush, Y., Robineau, F., Hutton, C., Weiskopf, N., Vuilleumier, P., Van De Ville, D., & Scharnowski, F. (2019). No time for drifting: Comparing performance and applicability of signal detrending algorithms for real-time fMRI. NeuroImage, 191, 421–429. 10.1016/j.neuroimage.2019.02.058
  6. Davey, C. E., Grayden, D. B., Egan, G. F., & Johnston, L. A. (2013). Filtering induces correlation in fMRI resting state data. NeuroImage, 64, 728–740. 10.1016/j.neuroimage.2012.08.022
  7. Sladky, R., Friston, K. J., Tröstl, J., Cunnington, R., Moser, E., & Windischberger, C. (2011). Slice-timing effects and their correction in functional MRI. NeuroImage, 58(2), 588–594. 10.1016/j.neuroimage.2011.06.078
  8. Risk, B. B., Kociuba, M. C., & Rowe, D. B. (2018). Impacts of simultaneous multislice acquisition on sensitivity and specificity in fMRI. NeuroImage, 172, 538–553. 10.1016/j.neuroimage.2018.01.078
  9. Parker, D. B., & Razlighi, Q. R. (2019). The Benefit of Slice Timing Correction in Common fMRI Preprocessing Pipelines. Frontiers in Neuroscience, 13. 10.3389/fnins.2019.00821
  10. Triantafyllou, C., Hoge, R. D., & Wald, L. L. (2006). Effect of spatial smoothing on physiological noise in high-resolution fMRI. NeuroImage, 32(2), 551–557. 10.1016/j.neuroimage.2006.04.182
  11. Liu, P., Calhoun, V., & Chen, Z. (2017). Functional overestimation due to spatial smoothing of fMRI data. Journal of Neuroscience Methods, 291, 1–12. 10.1016/j.jneumeth.2017.08.003
  12. Pajula, J., & Tohka, J. (2014). Effects of spatial smoothing on inter-subject correlation based analysis of FMRI. Magnetic Resonance Imaging, 32(9), 1114–1124. 10.1016/j.mri.2014.06.001
  13. Mikl, M., Mareček, R., Hluštík, P., Pavlicová, M., Drastich, A., Chlebus, P., Brázdil, M., & Krupa, P. (2008). Effects of spatial smoothing on fMRI group inferences. Magnetic Resonance Imaging, 26(4), 490–503. 10.1016/j.mri.2007.08.006
  14. Alakörkkö, T., Saarimäki, H., Glerean, E., Saramäki, J., & Korhonen, O. (2017). Effects of spatial smoothing on functional brain networks. European Journal of Neuroscience, 46(9), 2471–2480. 10.1111/ejn.13717
  15. Kriegeskorte, N., & Bandettini, P. (2007). Analyzing for information, not activation, to exploit high-resolution fMRI. NeuroImage, 38(4), 649–662. 10.1016/j.neuroimage.2007.02.022