Skip to content

Commit

Permalink
RF: Generate t1w_brain from t1w and mask on demand for coregistration
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Aug 23, 2023
1 parent e4512c3 commit 7e21c75
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
2 changes: 2 additions & 0 deletions fmriprep/workflows/bold/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ def init_bold_fit_wf(
# fmt:off
workflow.connect([
(inputnode, bold_reg_wf, [
("t1w_preproc", "inputnode.t1w_preproc"),
("t1w_mask", "inputnode.t1w_mask"),
("t1w_dseg", "inputnode.t1w_dseg"),
# Undefined if --fs-no-reconall, but this is safe
("subjects_dir", "inputnode.subjects_dir"),
Expand Down
43 changes: 27 additions & 16 deletions fmriprep/workflows/bold/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def init_bold_reg_wf(
niu.IdentityInterface(
fields=[
'ref_bold_brain',
't1w_brain',
't1w_preproc',
't1w_mask',
't1w_dseg',
'subjects_dir',
'subject_id',
Expand Down Expand Up @@ -186,8 +187,10 @@ def init_bold_reg_wf(
('fsnative2t1w_xfm', 'inputnode.fsnative2t1w_xfm'),
('subjects_dir', 'inputnode.subjects_dir'),
('subject_id', 'inputnode.subject_id'),
('t1w_preproc', 'inputnode.t1w_brain'),
('t1w_mask', 'inputnode.t1w_mask'),
('t1w_dseg', 'inputnode.t1w_dseg'),
('t1w_brain', 'inputnode.t1w_brain')]),
]),
(bbr_wf, outputnode, [('outputnode.itk_bold_to_t1', 'itk_bold_to_t1'),
('outputnode.itk_t1_to_bold', 'itk_t1_to_bold'),
('outputnode.fallback', 'fallback')]),
Expand Down Expand Up @@ -526,13 +529,14 @@ def init_bbreg_wf(
niu.IdentityInterface(
[
'in_file',
'fsnative2t1w_xfm',
'fsnative2t1w_xfm', # BBRegister
'subjects_dir',
'subject_id', # BBRegister
'subject_id',
't1w_preproc', # FLIRT BBR
't1w_mask',
't1w_dseg',
't1w_brain',
]
), # FLIRT BBR
),
name='inputnode',
)
outputnode = pe.Node(
Expand Down Expand Up @@ -736,6 +740,7 @@ def init_fsl_bbr_wf(
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
from niworkflows.interfaces.freesurfer import PatchedLTAConvert as LTAConvert
from niworkflows.interfaces.freesurfer import PatchedMRICoregRPT as MRICoregRPT
from niworkflows.interfaces.nibabel import ApplyMask
from niworkflows.interfaces.reportlets.registration import FLIRTRPT
from niworkflows.utils.images import dseg_label as _dseg_label

Expand All @@ -757,13 +762,14 @@ def init_fsl_bbr_wf(
niu.IdentityInterface(
[
'in_file',
'fsnative2t1w_xfm',
'fsnative2t1w_xfm', # BBRegister
'subjects_dir',
'subject_id', # BBRegister
'subject_id',
't1w_preproc', # FLIRT BBR
't1w_mask',
't1w_dseg',
't1w_brain',
]
), # FLIRT BBR
),
name='inputnode',
)
outputnode = pe.Node(
Expand All @@ -780,6 +786,9 @@ def init_fsl_bbr_wf(
if bold2t1w_init == "header":
raise NotImplementedError("Header-based registration initialization not supported for FSL")

# Mask T1w_preproc with T1w_mask to make T1w_brain
mask_t1w_brain = pe.Node(ApplyMask(), name='mask_t1w_brain')

mri_coreg = pe.Node(
MRICoregRPT(
dof=bold2t1w_dof, sep=[4], ftol=0.0001, linmintol=0.01, generate_report=not use_bbr
Expand Down Expand Up @@ -809,12 +818,14 @@ def init_fsl_bbr_wf(
)
# fmt:off
workflow.connect([
(inputnode, mri_coreg, [('in_file', 'source_file'),
('t1w_brain', 'reference_file')]),
(inputnode, fsl2itk_fwd, [('t1w_brain', 'reference_file'),
('in_file', 'source_file')]),
(inputnode, fsl2itk_inv, [('in_file', 'reference_file'),
('t1w_brain', 'source_file')]),
(inputnode, mask_t1w_brain, [('t1w_preproc', 'in_file'),
('t1w_mask', 'in_mask')]),
(inputnode, mri_coreg, [('in_file', 'source_file')]),
(inputnode, fsl2itk_fwd, [('in_file', 'source_file')]),
(inputnode, fsl2itk_inv, [('in_file', 'reference_file')]),
(mask_t1w_brain, mri_coreg, [('out_file', 'reference_file')]),
(mask_t1w_brain, fsl2itk_fwd, [('out_file', 'reference_file')]),
(mask_t1w_brain, fsl2itk_inv, [('out_file', 'source_file')]),
(mri_coreg, lta_to_fsl, [('out_lta_file', 'in_lta')]),
(invt_bbr, fsl2itk_inv, [('out_file', 'transform_file')]),
(fsl2itk_fwd, outputnode, [('itk_transform', 'itk_bold_to_t1')]),
Expand Down

0 comments on commit 7e21c75

Please sign in to comment.