# Processing pipeline details¶

fmriprep adapts its pipeline depending on what data and metadata are available and are used as the input. For example, slice timing correction will be performed only if the SliceTiming metadata field is found for the input dataset.

A (very) high-level view of the simplest pipeline (for a single-band dataset with only one task, single-run, with no slice-timing information nor fieldmap acquisitions) is presented below:

(Source code, png, svg, pdf)

## T1w/T2w preprocessing¶

fmriprep.workflows.anatomical.init_anat_preproc_wf

(Source code, png, svg, pdf)

The anatomical sub-workflow begins by constructing an average image by conforming all found T1w images to RAS orientation and a common voxel size, and, in the case of multiple images, averages them into a single reference template (see Longitudinal processing).

### Brain extraction, brain tissue segmentation and spatial normalization¶

Then, the T1w image/average is skull-stripped using ANTs’ antsBrainExtraction.sh, which is an atlas-based brain extraction workflow.

Once the brain mask is computed, FSL fast is utilized for brain tissue segmentation.

Finally, spatial normalization to MNI-space is performed using ANTs’ antsRegistration in a multiscale, mutual-information based, nonlinear registration scheme. In particular, spatial normalization is done using the ICBM 2009c Nonlinear Asymmetric template (1×1×1mm) [Fonov2011].

### Longitudinal processing¶

In the case of multiple sessions, T1w images are merged into a single template image using FreeSurfer’s mri_robust_template. This template may be unbiased, or equidistant from all source images, or aligned to the first image (determined lexicographically by session label). For two images, the additional cost of estimating an unbiased template is trivial and is the default behavior, but, for greater than two images, the cost can be a slowdown of an order of magnitude. Therefore, in the case of three or more images, fmriprep constructs templates aligned to the first image, unless passed the --longitudinal flag, which forces the estimation of an unbiased template.

Note

The preprocessed T1w image defines the T1w space. In the case of multiple T1w images, this space may not be precisely aligned with any of the original images. Reconstructed surfaces and functional datasets will be registered to the T1w space, and not to the input images.

### Surface preprocessing¶

fmriprep.workflows.anatomical.init_surface_recon_wf

(Source code, png, svg, pdf)

fmriprep uses FreeSurfer to reconstruct surfaces from T1w/T2w structural images. If enabled, several steps in the fmriprep pipeline are added or replaced. All surface preprocessing may be disabled with the --fs-no-reconall flag.

If FreeSurfer reconstruction is performed, the reconstructed subject is placed in <output dir>/freesurfer/sub-<subject_label>/ (see FreeSurfer Derivatives).

Surface reconstruction is performed in three phases. The first phase initializes the subject with T1w and T2w (if available) structural images and performs basic reconstruction (autorecon1) with the exception of skull-stripping. Skull-stripping is skipped since the brain mask calculated previously is injected into the appropriate location for FreeSurfer. For example, a subject with only one session with T1w and T2w images would be processed by the following command:

recon-all -sd <output dir>/freesurfer -subjid sub-<subject_label> \ -i <bids-root>/sub-<subject_label>/anat/sub-<subject_label>_T1w.nii.gz \ -T2 <bids-root>/sub-<subject_label>/anat/sub-<subject_label>_T2w.nii.gz \ -autorecon1 \ -noskullstrip  The second phase imports the brainmask calculated in the T1w/T2w preprocessing sub-workflow. The final phase resumes reconstruction, using the T2w image to assist in finding the pial surface, if available. See init_autorecon_resume_wf() for details. Reconstructed white and pial surfaces are included in the report. If T1w voxel sizes are less than 1mm in all dimensions (rounding to nearest .1mm), submillimeter reconstruction is used, unless disabled with --no-submm-recon. In order to bypass reconstruction in fmriprep, place existing reconstructed subjects in <output dir>/freesurfer prior to the run. fmriprep will perform any missing recon-all steps, but will not perform any steps whose outputs already exist. lh.midthickness and rh.midthickness surfaces are created in the subject surf/ directory, corresponding to the surface half-way between the gray/white boundary and the pial surface. The smoothwm, midthickness, pial and inflated surfaces are also converted to GIFTI format and adjusted to be compatible with multiple software packages, including FreeSurfer and the Connectome Workbench. ### Refinement of the brain mask¶ Typically, the original brain mask calculated with antsBrainExtraction.sh will contain some innaccuracies including small amounts of MR signal from outside the brain. Based on the tissue segmentation of FreeSurfer (located in mri/aseg.mgz) and only when the Surface Processing step has been executed, FMRIPREP replaces the brain mask with a refined one that derives from the aseg.mgz file as described in fmriprep.interfaces.freesurfer.grow_mask. ## BOLD preprocessing¶ fmriprep.workflows.bold.base.init_func_preproc_wf (Source code, png, svg, pdf) Preprocessing of BOLD files is split into multiple sub-workflows described below. ### BOLD reference image estimation¶ fmriprep.workflows.bold.util.init_bold_reference_wf (Source code, png, svg, pdf) This workflow estimates a reference image for a BOLD series. When T1-saturation effects (“dummy scans” or non-steady state volumes) are detected, they are averaged and used as reference due to their superior tissue contrast. Otherwise, a median of motion corrected subset of volumes is used. The reference image is then used to calculate a brain mask for the BOLD signal using the fmriprep.workflows.bold.util.init_enhance_and_skullstrip_bold_wf. Further, the reference is fed to the head-motion estimation workflow and the registration workflow to map BOLD series into the T1w image of the same subject. ### Head-motion estimation¶ fmriprep.workflows.bold.hmc.init_bold_hmc_wf (Source code, png, svg, pdf) Using the previously estimated reference scan, FSL mcflirt is used to estimate head-motion. As a result, one rigid-body transform with respect to the reference image is written for each BOLD time-step. Additionally, a list of 6-parameters (three rotations, three translations) per time-step is written and fed to the confounds workflow. For a more accurate estimation of head-motion, we calculate its parameters before any time-domain filtering (i.e. slice-timing correction), as recommended in [Power2017]. ### Slice time correction¶ fmriprep.workflows.bold.stc.init_bold_stc_wf (Source code, png, svg, pdf) If the SliceTiming field is available within the input dataset metadata, this workflow performs slice time correction prior to other signal resampling processes. Slice time correction is performed using AFNI 3dTShift. All slices are realigned in time to the middle of each TR. Slice time correction can be disabled with the --ignore slicetiming command line argument. If a BOLD series has fewer than 5 usable (steady-state) volumes, slice time correction will be disabled for that run. ### T2* Driven Coregistration¶ fmriprep.workflows.bold.t2s.init_bold_t2s_wf (Source code, png, svg, pdf) If the --t2s-coreg command line argument is supplied with multi-echo BOLD data, a T2* map is generated. This T2* map is then used in place of the BOLD reference image to ref:register the BOLD series to the T1w image of the same subject <bold_reg>. ### Susceptibility Distortion Correction (SDC)¶ One of the major problems that affects EPI data is the spatial distortion caused by the inhomogeneity of the field inside the scanner. Please refer to Susceptibility Distortion Correction (SDC) for details on the available workflows. ### Pre-processed BOLD in native space¶ fmriprep.workflows.bold.resampling.init_bold_preproc_trans_wf (Source code, png, svg, pdf) A new preproc BOLD series is generated from the slice-timing corrected or the original data (if STC was not applied) in the original space. All volumes in the BOLD series are resampled in their native space by concatenating the mappings found in previous correction workflows (HMC and SDC if excecuted) for a one-shot interpolation process. Interpolation uses a Lanczos kernel. ### EPI to T1w registration¶ fmriprep.workflows.bold.registration.init_bold_reg_wf (Source code, png, svg, pdf) The reference EPI image of each run is aligned by the bbregister routine to the reconstructed subject using the gray/white matter boundary (FreeSurfer’s ?h.white surfaces). If FreeSurfer processing is disabled, FSL flirt is run with the BBR cost function, using the fast segmentation to establish the gray/white matter boundary. ### EPI to MNI transformation¶ fmriprep.workflows.bold.resampling.init_bold_mni_trans_wf (Source code, png, svg, pdf) This sub-workflow concatenates the transforms calculated upstream (see Head-motion estimation, Susceptibility Distortion Correction (SDC) –if fieldmaps are available–, EPI to T1w registration, and a T1w-to-MNI transform from T1w/T2w preprocessing) to map the EPI image to standard MNI space. It also maps the T1w-based mask to MNI space. Transforms are concatenated and applied all at once, with one interpolation (Lanczos) step, so as little information is lost as possible. ### EPI sampled to FreeSurfer surfaces¶ fmriprep.workflows.bold.resampling.init_bold_surf_wf (Source code, png, svg, pdf) If FreeSurfer processing is enabled, the motion-corrected functional series (after single shot resampling to T1w space) is sampled to the surface by averaging across the cortical ribbon. Specifically, at each vertex, the segment normal to the white-matter surface, extending to the pial surface, is sampled at 6 intervals and averaged. Surfaces are generated for the “subject native” surface, as well as transformed to the fsaverage template space. All surface outputs are in GIFTI format. ### Confounds estimation¶ fmriprep.workflows.bold.confounds.init_bold_confs_wf (Source code, png, svg, pdf) Given a motion-corrected fMRI, a brain mask, mcflirt movement parameters and a segmentation, the discover_wf sub-workflow calculates potential confounds per volume. Calculated confounds include the mean global signal, mean tissue class signal, tCompCor, aCompCor, Frame-wise Displacement, 6 motion parameters, DVARS, and, if the --use-aroma flag is enabled, the noise components identified by ICA-AROMA (those to be removed by the “aggressive” denoising strategy). Note: non-aggressive AROMA denoising is a fundamentally different procedure from its “aggressive” counterpart and cannot be performed only by using a set of noise regressors (a separate GLM with both noise and signal regressors needs to be used). Therefore instead of regressors FMRIPREP produces non-aggressive denoised 4D NIFTI files in the MNI space: *bold_space-MNI152NLin2009cAsym_variant-smoothAROMAnonaggr_brainmask.nii.gz Additionally, the MELODIC mix and noise component indices will be generated, so non-aggressive denoising can be manually performed in the T1w space with fsl_regfilt, e.g.: fsl_regfilt -i sub-<subject_label>_task-<task_id>_bold_space-T1w_preproc.nii.gz \ -f(cat sub-<subject_label>_task-<task_id>_bold_AROMAnoiseICs.csv) \
-d sub-<subject_label>_task-<task_id>_bold_MELODICmix.tsv \
-o sub-<subject_label>_task-<task_id>_bold_space-<space>_AromaNonAggressiveDenoised.nii.gz


A visualization of the AROMA component classification is also included in the HTML reports.