FastSurfer Flags¶
Next, you will learn hot wo specify the *fastsurfer-flags*
by replacing *fastsurfer-flags*
with your specific options.
The *fastsurfer-flags*
will usually at least include the subject directory (--sd
; Note, this will be the mounted path - /output
- for containers), the subject name/id (--sid
) and the path to the input image (--t1
). For example:
... --sd /output --sid test_subject --t1 /data/test_subject_t1.nii.gz --3T
Additionally, you can use --seg_only
or --surf_only
to only run a part of the pipeline or --no_biasfield
, --no_cereb
and --no_asegdkt
to switch off individual segmentation modules.
Here, we have also added the --3T
flag, which tells FastSurfer to register against the 3T atlas which is only relevant for the ICV estimation (eTIV).
In the following, we give an overview of the most important options. You can view a full list of options with
./run_fastsurfer.sh --help
Required arguments¶
--sd
: Output directory $SUBJECTS_DIR (equivalent to FreeSurfer setup –> $SUBJECTS_DIR/sid/mri; $SUBJECTS_DIR/sid/surf … will be created).--sid
: Subject ID for directory inside $SUBJECTS_DIR to be created ($SUBJECTS_DIR/sid/…)--t1
: T1 full head input (does not need to be bias corrected, global path). The network was trained with conformed images (UCHAR, 256x256x256, 0.7mm - 1mm voxels and standard slice orientation). These specifications are checked in the run_prediction.py script and the image is automatically conformed if it does not comply. Note, outputs will be in the conformed space (following the FreeSurfer standard).
Required for Docker when running surface module¶
--fs_license
: Path to FreeSurfer license key file (needed for the surface module and, if activated, the talairach registration--tal_reg
in the segmentation). For local installs, your local FreeSurfer license will automatically be detected (usually$FREESURFER_HOME/license.txt
or$FREESURFER_HOME/.license
). Use this flag if autodetection fails or if you use Docker with the surface module. To get a license, register (for free).
Segmentation pipeline arguments (optional)¶
--seg_only
: Only run the brain segmentation pipeline and skip the surface pipeline.--seg_log
: Name and location for the log-file for the segmentation. Default: $SUBJECTS_DIR/$sid/scripts/deep-seg.log--viewagg_device
: Define where the view aggregation should be run on. Can be “auto” or a device (see –device). By default, the program checks if you have enough memory to run the view aggregation on the GPU. The total memory is considered for this decision. If this fails, or you actively specify “cpu” view aggregation is run on the CPU. Equivalently, if you pass a different device, view aggregation will be run on that device (no memory check will be done).--device
: Select device for neural network segmentation (auto, cpu, cuda, cuda:<device_num>, mps), where cuda means Nvidia GPU, you can select which one e.g. “cuda:1”. Default: “auto”, check GPU and then CPU. “mps” is for native MAC installs to use the Apple silicon (M-chip) GPU.--asegdkt_segfile
: Name of the segmentation file, which includes the aparc+DKTatlas-aseg segmentations. Requires an ABSOLUTE Path! Default location: $SUBJECTS_DIR/$sid/mri/aparc.DKTatlas+aseg.deep.mgz--no_cereb
: Switch off the cerebellum sub-segmentation.--cereb_segfile
: Name of the cerebellum segmentation file. If not provided, this intermediate DL-based segmentation will not be stored, but only the merged segmentation will be stored (see –main_segfile). Requires an ABSOLUTE Path! Default location: $SUBJECTS_DIR/$sid/mri/cerebellum.CerebNet.nii.gz --no_biasfield
: Deactivate the biasfield correction and calculation of partial volume-corrected statistics in the segmentation modules.
Surface pipeline arguments (optional)¶
--surf_only
: Only run the surface pipeline. The segmentation created by FastSurferVINN must already exist in this case.--3T
: Only affects Talairach registration: use the 3T atlas instead of the 1.5T atlas (which is used if the flag is not provided). This gives better (more consistent with FreeSurfer) ICV estimates (eTIV) for 3T and better Talairach registration matrices, but has little impact on standard volume or surface stats.--fstess
: Use mri_tesselate instead of marching cube (default) for surface creation (not recommended, but more similar to FreeSurfer)--fsqsphere
: Use FreeSurfer default instead of novel spectral spherical projection for qsphere (also not recommended)--fsaparc
: Use FS aparc segmentations in addition to DL prediction (slower in this case and usually the mapped ones from the DL prediction are fine)--no_fs_T1
: Skip generation ofT1.mgz
(normalizednu.mgz
included in standard FreeSurfer output) and createbrainmask.mgz
directly fromnorm.mgz
instead. Saves 1:30 min.--no_surfreg
: Skip the surface registration (which createssphere.reg
) to safe time. Note,sphere.reg
will be needed for any cross-subject statistical analysis of thickness maps, so do not use this option if you plan to perform cross-subject analysis.
Some other flags (optional)¶
--threads
,--threads_seg
and--threads_surf
: Target number of threads for all modules, segmentation, and surface pipeline. The default (1
) tells FastSurfer to only use one core. Note, that the default value may change in the future for better performance on multi-core architectures. If threads for surface reconstruction is greater than 1, both hemispheres are processed in parallel with half the threads allocated to each hemisphere.--vox_size
: Forces processing at a specific voxel size. If a number between 0.7 and 1 is specified (below is experimental) the T1w image is conformed to that isotropic voxel size and processed. If “min” is specified (default), the voxel size is read from the size of the minimal voxel size (smallest per-direction voxel size) in the T1w image: If the minimal voxel size is bigger than 0.98mm, the image is conformed to 1mm isometric. If the minimal voxel size is smaller or equal to 0.98mm, the T1w image will be conformed to isometric voxels of that voxel size. The voxel size (whether set manually or derived) determines whether the surfaces are processed with highres options (below 1mm) or not.--py
: Command for python, used in both pipelines. Default: python3.10--conformed_name
: Name of the file in which the conformed input image will be saved. Default location: $SUBJECTS_DIR/$sid/mri/orig.mgz-h
,--help
: Prints help text
Full list of flags¶
$ ./run_fastsurfer.sh --help
Setting ENV variable FASTSURFER_HOME to script directory /home/runner/work/FastSurfer/FastSurfer/src.
Change via environment to location of your choice if this is undesired (export FASTSURFER_HOME=/dir/to/FastSurfer)
Usage: run_fastsurfer.sh --sid <sid> --sd <sdir> --t1 <t1_input> [OPTIONS]
run_fastsurfer.sh takes a T1 full head image and creates:
(i) a segmentation using FastSurferVINN (equivalent to FreeSurfer
aparc.DKTatlas+aseg.mgz)
(ii) surfaces, thickness etc as a FS subject dir using recon-surf
FLAGS:
--fs_license <license> Path to FreeSurfer license key file. Register at
https://surfer.nmr.mgh.harvard.edu/registration.html
for free to obtain it if you do not have FreeSurfer
installed already
--sid <subjectID> Subject ID to create directory inside $SUBJECTS_DIR
--sd <subjects_dir> Output directory $SUBJECTS_DIR (or pass via env var)
--t1 <T1_input> T1 full head input (not bias corrected). Requires an
ABSOLUTE Path!
--asegdkt_segfile <filename>
Name of the segmentation file, which includes the
aparc+DKTatlas-aseg segmentations.
Requires an ABSOLUTE Path! Default location:
$SUBJECTS_DIR/$sid/mri/aparc.DKTatlas+aseg.deep.mgz
--vox_size <0.7-1|min> Forces processing at a specific voxel size.
If a number between 0.7 and 1 is specified (below
is experimental) the T1w image is conformed to
that voxel size and processed.
If "min" is specified (default), the voxel size is
read from the size of the minimal voxel size
(smallest per-direction voxel size) in the T1w
image:
If the minimal voxel size is bigger than 0.98mm,
the image is conformed to 1mm isometric.
If the minimal voxel size is smaller or equal to
0.98mm, the T1w image will be conformed to
isometric voxels of that voxel size.
The voxel size (whether set manually or derived)
determines whether the surfaces are processed with
highres options (below 1mm) or not.
--edits Enables manual edits by replacing select intermediate/
result files by manedit substitutes (*.manedit.<ext>).
Segmentation: <asegdkt_segfile> and <mask_name>.
Surface: Disables check for existing recon-surf.sh run;
edits of mri/wm.mgz and brain.finalsurfs.mgz
as well as FreeSurfer-style WM control points.
--version <info> Print version information and exit; <info> is optional.
<info> may be empty, just prints the version number,
+git_branch also prints the current branch, and any
combination of +git, +checkpoints, +pip to print
additional for the git status, the checkpoints and
installed python packages.
-h --help Print Help
PIPELINES:
By default, both the segmentation and the surface pipelines are run.
SEGMENTATION PIPELINE:
--seg_only Run only FastSurferVINN (generate segmentation, do not
run surface pipeline)
--seg_log <seg_log> Log-file for the segmentation (FastSurferVINN, CerebNet,
HypVINN)
Default: $SUBJECTS_DIR/$sid/scripts/deep-seg.log
--conformed_name <conf.mgz>
Name of the file in which the conformed input
image will be saved. Requires an ABSOLUTE Path!
Default location:
$SUBJECTS_DIR/$sid/mri/orig.mgz.
--no_biasfield Create a bias field corrected image and enable the
calculation of partial volume-corrected stats-files.
--norm_name Name of the biasfield corrected image
Default location:
$SUBJECTS_DIR/$sid/mri/orig_nu.mgz
--tal_reg Perform the talairach registration for eTIV estimates
in --seg_only stream and stats files (is affected by
the --3T flag, see below). Manual talairach
registrations are not replaced in --edits mode.
MODULES:
By default, all modules are run.
ASEGDKT MODULE:
--no_asegdkt Skip the asegdkt segmentation (aseg+aparc/DKT segmentation)
--asegdkt_segfile <filename>
Name of the segmentation file, which includes the
aseg+aparc/DKTatlas segmentations.
Requires an ABSOLUTE Path! Default location:
$SUBJECTS_DIR/$sid/mri/aparc.DKTatlas+aseg.deep.mgz
--no_biasfield Deactivate the calculation of partial volume-corrected
statistics.
CEREBELLUM MODULE:
--no_cereb Skip the cerebellum segmentation (CerebNet segmentation)
--asegdkt_segfile <seg_input>
Name of the segmentation file (similar to aparc+aseg)
for cerebellum localization (typically the output of the
APARC module (see above). Requires an ABSOLUTE Path!
Default location:
$SUBJECTS_DIR/$sid/mri/aparc.DKTatlas+aseg.deep.mgz
--cereb_segfile <seg_output>
Name of DL-based segmentation file of the cerebellum.
This segmentation is always at 1mm isotropic
resolution, since inference is always based on a
1mm conformed image, if the conformed image is *NOT*
already an 1mm image, an additional conformed image
at 1mm will be stored at the --conformed_name, but
with an additional file suffix of ".1mm".
Requires an ABSOLUTE Path! Default location:
$SUBJECTS_DIR/$sid/mri/cerebellum.CerebNet.nii.gz
--no_biasfield Deactivate the calculation of partial volume-corrected
statistics.
HYPOTHALAMUS MODULE (HypVINN):
--no_hypothal Skip the hypothalamus segmentation.
--no_biasfield This option implies --no_hypothal, as the hypothalamus
sub-segmentation requires biasfield-corrected images.
--t2 <T2_input> *Optional* T2 full head input (does not have to be bias
corrected, a mandatory biasfield correction step is
performed). Requires an ABSOLUTE Path!
--reg_mode <none|coreg|robust>
Ignored, if no T2 image is passed.
Specifies the registration method used to register T1
and T2 images. Options are 'coreg' (default) for
mri_coreg, 'robust' for mri_robust_register, and 'none'
to skip registration (this requires T1 and T2 are
externally co-registered).
--qc_snap Create QC snapshots in $SUBJECTS_DIR/$sid/qc_snapshots
to simplify the QC process.
SURFACE PIPELINE:
--surf_only Run surface pipeline only. The segmentation input has
to exist already in this case.
--3T Use the 3T atlas for talairach registration (gives better
etiv estimates for 3T MR images, default: 1.5T atlas).
Resource Options:
--device Set device on which inference should be run ("cpu" for
CPU, "cuda" for Nvidia GPU, or pass specific device,
e.g. cuda:1), default check GPU and then CPU.
--viewagg_device <str> Define where the view aggregation should be run on.
Can be "auto" or a device (see --device). By default,
the program checks if you have enough memory to run
the view aggregation on the gpu. The total memory is
considered for this decision. If this fails, or you
actively overwrote the check with setting with "cpu"
view agg is run on the cpu. Equivalently, if you
pass a different device, view agg will be run on that
device (no memory check will be done).
--threads <int> Set openMP and ITK threads to <int> or "max", also
--threads_seg <int> for definition of threads specific to segmentation
--threads_surf <int> and surface reconstruction (parallel hemispheres if
at number of threads for surfaces >=2, default: 1).
--batch <batch_size> Batch size for inference (default: 1).
--py <python_cmd> Command for python, used in both pipelines.
Default: "python3.10 -s"
(-s: do no search for packages in home directory)
Dev Flags:
--ignore_fs_version Switch on to avoid check for FreeSurfer version.
Program will terminate if the supported version
(see recon-surf.sh) is not sourced. Can be used for
testing dev versions.
--fstess Switch on mri_tesselate for surface creation (default:
mri_mc).
--fsqsphere Use FreeSurfer iterative inflation for qsphere
(default: spectral spherical projection).
--fsaparc Additionally create FS aparc segmentations and ribbon.
Skipped by default (--> DL prediction is used which
is faster, and usually these mapped ones are fine).
--no_fs_T1 Do not generate T1.mgz (normalized nu.mgz included in
standard FreeSurfer output) and create brainmask.mgz
directly from norm.mgz instead. Saves 1:30 min.
--no_surfreg Do not run Surface registration with FreeSurfer (for
cross-subject correspondence), Not recommended, but
speeds up processing if you e.g. just need the
segmentation stats!
--allow_root Allow execution as root user.
Longitudinal Flags (non-expert users should use long_fastsurfers.sh for
sequential processing of longitudinal data):
--base Longitudinal template (base) processing.
Only ASEGDKT in segmentation and differences in the
surface module. Requires longitudinal template
preparation (recon-surf/long_prepare_template.sh) to
be completed beforehand! No T2 can be passed. Also
no T1 is explicitly passed, as it is taken from
within the prepared template directory.
--long <baseid> Longitudinal time point processing.
Requires the base (template) already exists in the
same SUBJECTS_DIR under the SID <baseid>.
Processing is identical to the regular cross-sectional
pipeline for segmentation. Surface module skips
many steps and initializes from subject template.
No T2 can be passed. Also no T1 is explicitly passed,
as it is taken from the prepared template directory.
REFERENCES:
If you use this for research publications, please cite:
Henschel L, Conjeti S, Estrada S, Diers K, Fischl B, Reuter M, FastSurfer - A
fast and accurate deep learning based neuroimaging pipeline, NeuroImage 219
(2020), 117012. https://doi.org/10.1016/j.neuroimage.2020.117012
Henschel L*, Kuegler D*, Reuter M. (*co-first). FastSurferVINN: Building
Resolution-Independence into Deep Learning Segmentation Methods - A Solution
for HighRes Brain MRI. NeuroImage 251 (2022), 118933.
http://dx.doi.org/10.1016/j.neuroimage.2022.118933
For cerebellum sub-segmentation:
Faber J*, Kuegler D*, Bahrami E*, et al. (*co-first). CerebNet: A fast and
reliable deep-learning pipeline for detailed cerebellum sub-segmentation.
NeuroImage 264 (2022), 119703.
https://doi.org/10.1016/j.neuroimage.2022.119703
For hypothalamus sub-segemntation:
Estrada S, Kuegler D, Bahrami E, Xu P, Mousa D, Breteler MMB, Aziz NA, Reuter M.
FastSurfer-HypVINN: Automated sub-segmentation of the hypothalamus and adjacent
structures on high-resolutional brain MRI. Imaging Neuroscience 2023; 1 1–32.
https://doi.org/10.1162/imag_a_00034
For longitudinal processing:
Reuter M, Schmansky NJ, Rosas HD, Fischl B. Within-subject template estimation
for unbiased longitudinal image analysis, NeuroImage 61:4 (2012).
https://doi.org/10.1016/j.neuroimage.2012.02.084