Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add a --skull-strip-t1w argument to skip brain extraction #2039

Merged
merged 4 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/workflows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ single reference template (see `Longitudinal processing`_).
t1w=['sub-01/anat/sub-01_T1w.nii.gz'],
)

.. important::

Occasionally, openly shared datasets may contain preprocessed anatomical images
as if they are unprocessed.
In the case of brain-extracted (skull-stripped) T1w images, attempting to perform
brain extraction again will often have poor results and may cause *fMRIPrep* to crash.
By default, *fMRIPrep* will attempt to detect these cases using a heuristic to check if the
T1w image is already masked.
If this heuristic fails, and you know your images are skull-stripped, you can skip brain
extraction with ``--skull-strip-t1w skip``.
Likewise, if you know your images are not skull-stripped and the heuristic incorrectly
determines that they are, you can force skull stripping with ``--skull-strip-t1w force``.
The default behavior of detecting pre-extracted brains may be explicitly requested with
``---skull-strip-t1w auto``, which will use a heuristic to check if each image is
already masked.

See also *sMRIPrep*'s
:py:func:`~smriprep.workflows.anatomical.init_anat_preproc_wf`.

Expand Down
18 changes: 18 additions & 0 deletions fmriprep/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ def _bids_filter(value):
g_ants.add_argument('--skull-strip-fixed-seed', action='store_true',
help='do not use a random seed for skull-stripping - will ensure '
'run-to-run replicability when used with --omp-nthreads 1')
g_ants.add_argument(
'--skull-strip-t1w', action='store', choices=('auto', 'skip', 'force'), default='force',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'--skull-strip-t1w', action='store', choices=('auto', 'skip', 'force'), default='force',
'--skull-strip-t1w', action='store', choices=('auto', 'skip', 'force'), default='auto',

help="determiner for T1-weighted skull stripping ('force' ensures skull "
"stripping, 'skip' ignores skull stripping, and 'auto' applies brain extraction "
"based on the outcome of a heuristic to check whether the brain is already masked).")

# Fieldmap options
g_fmap = parser.add_argument_group('Specific options for handling fieldmaps')
Expand Down Expand Up @@ -347,6 +352,19 @@ def parse_args(args=None, namespace=None):
'Per-process threads (--omp-nthreads=%d) exceed total '
'threads (--nthreads/--n_cpus=%d)', config.nipype.omp_nthread, config.nipype.nprocs)

# Inform the user about the risk of using brain-extracted images
if config.workflow.skull_strip_t1w == "auto":
build_log.warning("""\
Option ``--skull-strip-t1w`` was set to 'auto'. A heuristic will be \
applied to determine whether the input T1w image(s) have already been skull-stripped.
If that were the case, brain extraction and INU correction will be skipped for those T1w \
inputs. Please, BEWARE OF THE RISKS TO THE CONSISTENCY of results when using varying \
processing workflows across participants. To determine whether a participant has been run \
through the shortcut pipeline (meaning, brain extraction was skipped), please check the \
citation boilerplate. When reporting results with varying pipelines, please make sure you \
mention this particular variant of fMRIPrep listing the participants for which it was \
applied.""")

bids_dir = config.execution.bids_dir
output_dir = config.execution.output_dir
work_dir = config.execution.work_dir
Expand Down
3 changes: 3 additions & 0 deletions fmriprep/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ class workflow(_Config):
"""Fix a seed for skull-stripping."""
skull_strip_template = "OASIS30ANTs"
"""Change default brain extraction template."""
skull_strip_t1w = "force"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
skull_strip_t1w = "force"
skull_strip_t1w = "auto"

"""Skip brain extraction of the T1w image (default is ``force``, meaning that
*fMRIPrep* will run brain extraction of the T1w)."""
spaces = None
"""Keeps the :py:class:`~niworkflows.utils.spaces.SpatialReferences`
instance keeping standard and nonstandard spaces."""
Expand Down
2 changes: 1 addition & 1 deletion fmriprep/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def init_single_subject_wf(subject_id):
output_dir=str(config.execution.output_dir),
reportlets_dir=reportlets_dir,
skull_strip_fixed_seed=config.workflow.skull_strip_fixed_seed,
skull_strip_mode='force',
skull_strip_mode=config.workflow.skull_strip_t1w,
skull_strip_template=Reference.from_string(
config.workflow.skull_strip_template)[0],
spaces=spaces,
Expand Down