5. Defacing Workflow¶
5.1. Introduction¶
Defacing MRI data is crucial for protecting participant privacy in neuroimaging research. Structural brain MRI include facial features that can be reconstructed and used to identify individuals. Defacing removes these features while preserving brain anatomy for analysis.
5.2. Requirements¶
CPU |
RAM |
|---|---|
1 |
5 GB |
5.3. Description¶
Processing Steps
Defacing T1w image We use the defacing method that is provided as part of the standard FSL distribution under the command
fsl_deface[1]. Similar to other established defacing tools, such asmri_deface[2] andpydeface[3], the method relies on linear registration to generate a mask that identifies facial voxels. Voxels within this mask are then set to zero to remove identifiable facial features. A key distinction offsl_defacecompared withmri_defaceandpydefaceis that it additionally removes the ears, providing a more comprehensive anonymization of head anatomy. This workflow is applied to T1-weighted structural images.Defacing T2w and FLAIR images The defacing mask obtained from the T1w image is propagated to other modalities through rigid alignement.
Quality Control
Correlation score For each aligned image, we compute its correlation with the MNI for T1w or to T1w for T2w and FLAIR reference image. Images are then sorted in ascending order of this score, allowing potential outliers to be easily identified.
Overlap score For each image, we compute the overlap ratio between the brain mask extracted using FreeSurfer’s deep‑learning–based
mri_synthstripmethod [4] and the corresponding defacing mask. Images are then sorted in ascending order of this score, allowing potential outliers to be easily identified.Manual inspection Following the overlap-based ranking, a manual quality control step is performed using the generated
defacemosaicfigure. This figure allows visual inspection of the defaced image and verification that facial/ear structures have been successfully removed. The most obvious outliers are thus removed.Thresholding The correlation score is thresholded at 0.5, meaning that if an image is not roughly registered to the template, the preprocessing is considered invalid. The overlap score is thresholded at 5%, meaning that if the defacing mask removes a substantial portion of the brain, the preprocessing is considered invalid. Images with a correlation lower than 0.5 or an overlap greater than 5% are flagged as low‑quality.
5.4. Outputs¶
The defacing directory contains subject-level results, logs, and
quality-control outputs.
The structure is organized following the brainprep ontology.
defacing/
├── dataset_description.json
├── figures
│ ├── histogram_mean_correlation_<T1w|T2w|FLAIR>.png
│ └── histogram_overlap_<T1w|T2w|FLAIR.png
├── log
│ ├── report_<timestamp>.rst
│ └── commands_<timestamp>.rst
├── quality_check
│ ├── mask_overlap_<T1w|T2w|FLAIR>.tsv
│ └── mean_correlations_<T1w|T2w|FLAIR>.tsv
└── subjects
└── sub-01
└── ses-01
├── figures
│ └── sub-01_ses-01_run-01_mod-<T1w|T2w|FLAIR>_defacemosaic.png
├── log
│ ├── report_<timestamp>.rst
│ └── commands_<timestamp>.rst
├── quality_check
│ ├── sub-01_ses-01_run-01_mod-<T1w|T2w|FLAIR>_corr.tsv
│ └── sub-01_ses-01_run-01_mod-<T1w|T2w|FLAIR>_maskdiff.tsv
├── sub-01_ses-01_run-01_mod-<T1w|T2w|FLAIR>_affine.mat
├── sub-01_ses-01_run-01_mod-<T1w|T2w|FLAIR>_defacemask.nii.gz
├── sub-01_ses-01_run-01_mod-<T1w|T2w|FLAIR>_maskdiff.tsv
└── sub-01_ses-01_run-01_mod-<T1w|T2w|FLAIR>.nii.gz
Description of contents:
dataset_description.jsonMetadata describing the process, including versioning and processing information.figures/histogram_mean_correlation_<T1w|T2w|FLAIR>.pngImage correlation-to-reference image distribution and applied threshold.figures/histogram_overlap_<T1w|T2w|FLAIR>.pngImage overlap distribution and applied threshold.logs/report_<timestamp>.rstContains group-level workflow steps and parameters.log/commands_<timestamp>.rstContains group-level executed commands.quality_check/mask_overlap_<T1w|T2w|FLAIR>.tsvTable containing the overlap score for each subject/session/run. The table includes a binaryqccolumn indicating the quality control result.quality_check/mean_correlations_<T1w|T2w|FLAIR>.tsvTable containing the correlation score for each subject/session/run. The table includes a binaryqccolumn indicating the quality control result.subjects/sub-<id>/ses-<id>/figures/sub-01_ses-01_run-01_mod-<T1w|T2w|FLAIR>_defacemosaic.pngA visual mosaic showing defacing masks on some slices for quick quality check.subjects/sub-<id>/ses-<id>/logs/report_<timestamp>.rstContains subject-level workflow steps and parameters.subjects/sub-<id>/ses-<id>/log/commands_<timestamp>.rstContains subject-level executed commands.subjects/sub-<id>/ses-<id>/quality_check/sub-01_ses-01_run-01_mod-<T1w|T2w|FLAIR>_corr.tsvTable containing the correlation score.subjects/sub-<id>/ses-<id>/quality_check/sub-01_ses-01_run-01_mod-<T1w|T2w|FLAIR>_maskdiff.tsvA table containing voxel counts and physical volumes (in mm³) for the brain/defacing masks and their intersection.subjects/sub-<id>/ses-<id>/sub-01_ses-01_run-01_mod-<T1w|T2w|FLAIR>_affine.txtAffine transformation parameters (12 DOF) used to align the T1w image to the MNI template or rigid transformation parameters (6 DOF) used to coregister the T2w or FLAIR image to the T1w image.subjects/sub-<id>/ses-<id>/sub-01_ses-01_run-01_mod-<T1w|T2w|FLAIR>_defacemask.nii.gzThe binary mask identifying voxels removed during defacing (face and ears).subjects/sub-<id>/ses-<id>/sub-01_ses-01_run-01_mod-<T1w|T2w|FLAIR>.nii.gzThe final defaced T1w, T2w or FLAIR image with facial/ear structures removed.
5.5. Featured examples¶
Defacing
Explore how to perform this analysis.