# Anatomical Preprocessing¶

## Skull-Stripping¶

Skull-stripping is the removal of skull and other non-brain tissue like dura and eyes from anatomical images, which could otherwise complicate co-registration and normalization steps.

C-PAC provides options for configuring skull-stripping - users can select:

### Configuring CPAC to run Skull-Stripping:¶

NOTE: If providing your own brain mask for extraction, you can leave the following options at default. The skull-stripping tools will not run if a brain mask is found in the data configuration file.

1. Inputs already skull stripped? - [On,Off]: If inputs are already skull stripped (i.e. the structural input data is brain-only) then you can toggle this option to off.
2. Which tool for skull-stripping? - [FSL, AFNI, FSL/AFNI]: Chose if you’d like to use FSL BET, AFNI 3dSkullStrip, or run both options in parallel.

### Configuring AFNI 3dSkullStrip options:¶

Note: These options are pre-set for AFNI 3dSkullStrip’s default values. These do not need to be modified unless you are looking to optimize the results of skull-stripping for your particular dataset.

1. Shrink factor - [0.6]: Set the threshold value for controlling the brain vs non-brain voxels
2. Vary shrink factor - [On,Off]: Vary the shrink factor at every iteration of the algorithm. This prevents the likelihood of surface getting stuck in large pools of CSF before reaching the outer surface of the brain. Default is On.
3. Shrink factor bottom limit - [0.4]: The shrink factor bottom limit sets the lower threshold when varying the shrink factor. Default is 0.4, for when edge detection is used (which is On by default),otherwise the default value is 0.4.
4. Avoid ventricles - [On,Off]: Avoid ventricles while skull stripping. Default is On.
5. Number of iterations - [250]: Set the number of iterations. Default is 250. The number of iterations should depend upon the density of your mesh. Default is 250.
6. Pushout - [On, Off]: While expanding, consider the voxels above and not only the voxels below. Default is On
7. Touchup - [On,Off]: Perform touchup operations at the end to include areas not covered by surface expansion.
8. Fill hole option - [10]: Give the maximum number of pixels on either sid of the hole that can be filled. The default is 10 only if ’Touchup’ is On. Otherwise default is 0.
9. NN smooth - [72]: Perform final surface smoothing after all iterations. Default is 20.
10. Avoid eyes - [On,Off]: Avoid eyes while skull stripping. Default is On.
11. Use edge - [On,Off]: Use edge detection to reduce leakage into meninges. Default is On.
12. Fractional expansion - [0.1]: Speed of expansion. Default Value is 0.1
13. Push to edge - [Off,On]: Perform aggressive push to edge, this might cause leakage. Default is Off.
14. Use Skull - [Off, On]: Use the outer skull to limit expansion of surface into the skull in case of very strong shading artifacts. Use this only if you leakage into the skull.
15. Perc_init - [0]: Percentage of segments allowed to intersect surface.It is typically a number between 0 and 0.1, but can include negative values (which implies no testing for intersection). Default is 0.
16. Max_inter_iter - [4]: Number of iterations to remove intersection problems. With each iteration, the program automatically increases the amount of smoothing to get rid of intersections. Default is 4.
17. Fac - [1]: Multiply input dataset by FAC if range of values is too small. Default value is 1.
18. blur_fwhm - [2]: Blur datasets after spatial normalization.Default value is 2.

### Configuring FSL BET options:¶

Note: These options are pre-set for FSL BET’s default values. These do not need to be modified unless you are looking to optimize the results of skull-stripping for your particular dataset.

1. Frac - [0.5]: Set the threshold value controlling the brain vs non-brain voxels. Default is 0.5
2. Mask - [Off, On]: Mask created along with skull stripping. Default option is Off.
3. Mesh - [Off, On]: Mesh created along with skull stripping. Default is Off.
4. Outline - [Off, On]: Create a surface outline image, Default is Off.
7. Reduce bias - [Off, On]: Reduce bias and cleanup neck. Mutually exclusive with functional, reduce_bias,robust,padding, remove_eyes,surfaces.
8. Remove_bias - [Off,On]: Eyes and optic nerve cleanup. Mutually exclusive with functional, reduce_bias,robust,padding,remove_eyes, surfaces.
9. Robust - [Off, On]: Robust brain center estimation. Mutually exclusive with functional, reduce_bias, robust,padding,remove_eyes,surfaces.
10. Skull - [Off,On]: Create a Skull Image. Default is Off.
11. Surfaces - [Off, On]: Get additional skull and scalp surfaces by running bet2 and betsurf. This is mutually exclusive with reduce bias, robust,padding, remove_eyes.
12. Threshold - [Off,On]: Apply thresholding to segmented brain image and mask.Default is Off.
13. Vertical gradient - [Off,On]: Vertical gradient un fractional intensity threshold. Within the range of (-1,1).

## Anatomical Registration¶

In order to compare brain activations between subjects, individual functional and anatomical images must first be transformed to match a common template. The most commonly used template (MNI152) is maintained by the Montreal Neurological Institute, and is created by combining data from the brains of many different individuals to create an “average” brain. The image below shows how an individual brain is warped to match the shape of the template.

C-PAC provides the option of either using FSL (FLIRT and FNIRT) or Advanced Normalization Tools (ANTS) to register images. Although the use of ANTS requires an extra step during the C-PAC install process, we have found its results to be significantly better than those produced by FSL (a conclusion supported by a recent systematic analysis by Klein et al.).

During registration, individual anatomical images are first transformed to match the common template. Then, the functional data for each subject is registered to their own transformed anatomical image. Finally, functional derivative files are transformed to the common template. For more detail on how C-PAC computes these steps, please see the Registration Page of the developer documentation.

By default, C-PAC will register subject brains to the MNI152 template included with FSL. Users wishing to register their data to a different template (such as a group specific template) can specify alternative template files.

## Configuring CPAC to Run Anatomical Registration¶

1. Anatomical Template Resolution - [1mm, 2mm, 3mm, 4mm]: The resolution to which anatomical images should be transformed during registration. This is the resolution at which processed anatomical files will be output.
2. Anatomical Template (Brain Only) - [path]: Template to be used during registration. It is not necessary to change this path unless you intend to use a non-standard template.
3. Anatomical Template (With Skull) - [path]: Template to be used during registration. It is not necessary to change this path unless you intend to use a non-standard template.
4. Anatomical to Template Registration Method - [ANTS, FSL, ANTS & FSL]: Registration method(s) to be used. Options are ANTS, FSL, or both.
5. FSL FNIRT Configuration File - [path]: Configuration file specifying settings used during registration. Required if FSL is selected as the registration method. This file can be found in the /etc/flirtsch directory of your FSL install.
6. FSL FNIRT Reference Mask - [path]: A reference mask to be used by FNIRT.
7. Use skull-on image to calculate transform? (ANTS only) - [Off, On]: Register skull-on anatomical image to template. Calculating the transform with skull-stripped images is reported to be better, but it requires very high-quality skull-stripping. If skull-stripping is imprecise, registration with skull is preferred. Note: This option only affects ANTS due to the fact that FNIRT already uses skull-on images for calculating warps.
8. Inputs Already Skull-stripped? - [On, Off]: Disables skull-stripping on the anatomical inputs if they are already skull-stripped.

### Configuration Without the GUI¶

The following key/value pairs must be defined in your pipeline configuration YAML for C-PAC to run anatomical preprocessing:

Key Description Potential Values
resolution_for_anat The resolution to which anatomical images should be transformed during registration. 1mm,2mm,3mm,4mm
template_brain_only_for_anat Template to be used during registration. Normally the default value (seen in the example YAML) is fine. A path (e.g., $FSLDIR/data/standard/MNI152_T1_${resolution_for_anat}_brain.nii.gz).
template_skull_for_anat Template to be used during registration. Normally the default value (seen in the example YAML) is fine. A path (e.g., $FSLDIR/data/standard/MNI152_T1_${resolution_for_anat}_brain.nii.gz).
regOption Use either ANTS or FSL (FLIRT and FNIRT) as your anatomical registration method. A list containing ‘ANTS’, ‘FSL’, or both (e.g., [‘FSL’]).
fnirtConfig Configuration file to be used by FSL to set FNIRT parameters. A template name (e.g., ‘T1_2_MNI152_2mm’).
ref_mask Configuration file to be used by FSL to set FNIRT parameters. A path (e.g., $FSLDIR/data/standard/MNI152_T1_${resolution_for_anat}_brain_mask_dil.nii.gz).
regWithSkull Register skull-on anatomical image to a template. A list where ‘1’ represents ‘yes’ and ‘0’ represents ‘no’ (e.g., ‘[1]’).
already_skullstripped Disables skull-stripping on the anatomical inputs if they are already skull-stripped. A list where ‘1’ represents ‘yes’ and ‘0’ represents ‘no’ (e.g., ‘[1]’).

The box below contains an example of what these parameters might look like when defined in the YAML:

resolution_for_anat : 2mm
template_brain_only_for_anat : /usr/share/fsl/5.0/data/standard/MNI152_T1_${resolution_for_anat}_brain.nii.gz template_skull_for_anat : /usr/share/fsl/5.0/data/standard/MNI152_T1_${resolution_for_anat}.nii.gz
regOption : ['ANTS']
fnirtConfig : T1_2_MNI152_2mm
ref_mask : $FSLDIR/data/standard/MNI152_T1_${resolution_for_anat}_brain_mask_symmetric_dil.nii.gz
regWithSkull : [0]


## Anatomical Tissue Segmentation¶

C-PAC uses FSL/FAST to automatically segment brain images into white matter, gray matter, and CSF. This is done using probability maps that contain information about the likelihood that a given voxel will be of a particular tissue type. Users specify a probability threshold such that voxels meeting a minimum probability of being a particular tissue will be classified as such. This results in masks containing voxels of only a single tissue type.

The default tissue probability maps (referred to as Prior Probability Maps) used during segmentation are based on information from a large number of brains, and are based on the priors distributed with FSL and are included in the “Image Resource Files” package downloaded during installation. For more detail on how CPAC computes these steps, please see the Segmentation Page of the developer documentation.

If you would like to use different priors, they must first be binarized such that for each voxel the probability for each tissue type is set to either 0% or 100%.

The following bash script will binarize existing priors:

# Define what kind of priors to generate (gray, white, or csf)
tissue=gray

# Define threshold to use when binarizing data
threshold=0.5

# Copy existing priors (in this example, from FSL)
3dcopy $FSL_DIR/data/standard/tissuepriors/avg152T1_${tissue}.hdr avg152T1_${tissue}.nii.gz # Binarize image using threshold set above fslmaths avg152T1_${tissue}.nii.gz -thr $threshold -bin avg152T1_${tissue}_2mm_bin


## Configuring CPAC to Run Anatomical Tissue Segmentation¶

1. Run Tissue Segmentation - [On, Off, On/Off]: Automatically segment anatomical images into white matter, gray matter, and CSF based on prior probability maps.
2. Priors Directory - [path]: Full path to a directory containing binarized prior probability maps. These maps are included as part of the ‘Image Resource Files’ package available on the Install page of the User Guide. It is not necessary to change this path unless you intend to use non-standard priors.
3. White Matter Prior Probability Map - [path]: Full path to a binarized White Matter prior probability map. It is not necessary to change this path unless you intend to use non-standard priors.
4. Gray Matter Prior Probability Map - [path]: Full path to a binarized Gray Matter prior probability map. It is not necessary to change this path unless you intend to use non-standard priors.
5. CSF Prior Probability Map - [path]: Full path to a binarized CSF prior probability map. It is not necessary to change this path unless you intend to use non-standard priors.

### Configuration Without the GUI¶

The following key/value pairs must be defined in your pipeline configuration YAML for C-PAC to run anatomical tissue segmentation:

Key Description Potential Values
runSegmentationPreprocessing Automatically segment anatomical images into white matter, gray matter, and CSF based on prior probability maps. A list where ‘1’ represents ‘yes’ and ‘0’ represents ‘no’ (e.g., ‘[1]’).
priors_path Full path to a directory containing binarized prior probability maps. These maps are included as part of the ‘CPAC Image Resource Files’ package from installation. It is not necessary to change this path unless you intend to use non-standard priors. A path (e.g., $FSLDIR/data/standard/tissuepriors/${resolution_for_anat}).
PRIORS_WHITE Full path to a binarized White Matter prior probability map. It is not necessary to change this path unless you intend to use non-standard priors. A path (e.g., $priors_path/avg152T1_white_bin.nii.gz). PRIORS_GRAY Full path to a binarized Gray Matter prior probability map. It is not necessary to change this path unless you intend to use non-standard priors. A path (e.g.,$priors_path/avg152T1_gray_bin.nii.gz).
PRIORS_CSF Full path to a binarized CSF prior probability map. It is not necessary to change this path unless you intend to use non-standard priors. A path (e.g., $priors_path/avg152T1_csf_bin.nii.gz). The box below contains an example of what these parameters might look like when defined in the YAML: runSegmentationPreprocessing : [1] priors_path : /usr/share/fsl/5.0/data/standard/tissuepriors/${resolution_for_anat}
PRIORS_WHITE : $priors_path/avg152T1_white_bin.nii.gz PRIORS_GRAY :$priors_path/avg152T1_gray_bin.nii.gz
PRIORS_CSF : \$priors_path/avg152T1_csf_bin.nii.gz


## References¶

AFNI 3dSkullStrip

Smith, Stephen M., Fast robust automated brain extraction, Human Brain Mapping 2002, Volume 17 Issue 3, page 143-155.