-
Notifications
You must be signed in to change notification settings - Fork 301
[RTM] RF: Miscellaneous registration refactorings #741
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
Changes from all commits
0e75c2a
593fff3
7df22f8
6523ff9
7560f69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,7 +153,7 @@ def init_anat_preproc_wf(skull_strip_ants, output_spaces, template, debug, frees | |
FreeSurfer SUBJECTS_DIR | ||
subject_id | ||
FreeSurfer subject ID | ||
fs_2_t1_transform | ||
t1_2_fsnative_reverse_transform | ||
Affine transform from FreeSurfer subject space to T1w space | ||
surfaces | ||
GIFTI surfaces (gray/white boundary, midthickness, pial, inflated) | ||
|
@@ -174,7 +174,7 @@ def init_anat_preproc_wf(skull_strip_ants, output_spaces, template, debug, frees | |
fields=['t1_preproc', 't1_brain', 't1_mask', 't1_seg', 't1_tpms', | ||
't1_2_mni', 't1_2_mni_forward_transform', 't1_2_mni_reverse_transform', | ||
'mni_mask', 'mni_seg', 'mni_tpms', | ||
'subjects_dir', 'subject_id', 'fs_2_t1_transform', 'surfaces']), | ||
'subjects_dir', 'subject_id', 't1_2_fsnative_reverse_transform', 'surfaces']), | ||
name='outputnode') | ||
|
||
# 0. Reorient T1w image(s) to RAS and resample to common voxel space | ||
|
@@ -314,7 +314,7 @@ def len_above_thresh(in_list, threshold, longitudinal): | |
(surface_recon_wf, outputnode, [ | ||
('outputnode.subjects_dir', 'subjects_dir'), | ||
('outputnode.subject_id', 'subject_id'), | ||
('outputnode.fs_2_t1_transform', 'fs_2_t1_transform'), | ||
('outputnode.t1_2_fsnative_reverse_transform', 't1_2_fsnative_reverse_transform'), | ||
('outputnode.surfaces', 'surfaces')]), | ||
]) | ||
|
||
|
@@ -499,7 +499,7 @@ def init_surface_recon_wf(omp_nthreads, hires, name='surface_recon_wf'): | |
FreeSurfer SUBJECTS_DIR | ||
subject_id | ||
FreeSurfer subject ID | ||
fs_2_t1_transform | ||
t1_2_fsnative_reverse_transform | ||
FSL-style affine matrix translating from FreeSurfer T1.mgz to T1w | ||
surfaces | ||
GIFTI surfaces for gray/white matter boundary, pial surface, | ||
|
@@ -521,7 +521,8 @@ def init_surface_recon_wf(omp_nthreads, hires, name='surface_recon_wf'): | |
name='inputnode') | ||
outputnode = pe.Node( | ||
niu.IdentityInterface( | ||
fields=['subjects_dir', 'subject_id', 'fs_2_t1_transform', 'surfaces', 'out_report']), | ||
fields=['subjects_dir', 'subject_id', 't1_2_fsnative_reverse_transform', 'surfaces', | ||
'out_report']), | ||
name='outputnode') | ||
|
||
recon_config = pe.Node(FSDetectInputs(hires_enabled=hires), name='recon_config', | ||
|
@@ -542,6 +543,7 @@ def init_surface_recon_wf(omp_nthreads, hires, name='surface_recon_wf'): | |
fs_transform = pe.Node( | ||
fs.Tkregister2(fsl_out='freesurfer2subT1.mat', reg_header=True), | ||
name='fs_transform') | ||
fsl2lta = pe.Node(fs.utils.LTAConvert(out_lta=True), name='fsl2lta') | ||
|
||
autorecon_resume_wf = init_autorecon_resume_wf(omp_nthreads=omp_nthreads) | ||
gifti_surface_wf = init_gifti_surface_wf() | ||
|
@@ -572,12 +574,15 @@ def init_surface_recon_wf(omp_nthreads, hires, name='surface_recon_wf'): | |
# reoriented image | ||
(inputnode, fs_transform, [('t1w', 'target_image')]), | ||
(autorecon1, fs_transform, [('T1', 'moving_image')]), | ||
(inputnode, fsl2lta, [('t1w', 'target_file')]), | ||
(autorecon1, fsl2lta, [('T1', 'source_file')]), | ||
(fs_transform, fsl2lta, [('fsl_file', 'in_fsl')]), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @oesteban These are the new lines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM! |
||
# Output | ||
(autorecon_resume_wf, outputnode, [('outputnode.subjects_dir', 'subjects_dir'), | ||
('outputnode.subject_id', 'subject_id'), | ||
('outputnode.out_report', 'out_report')]), | ||
(gifti_surface_wf, outputnode, [('outputnode.surfaces', 'surfaces')]), | ||
(fs_transform, outputnode, [('fsl_file', 'fs_2_t1_transform')]), | ||
(fsl2lta, outputnode, [('out_lta', 't1_2_fsnative_reverse_transform')]), | ||
]) | ||
|
||
return workflow | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ | |
from niworkflows.nipype import logging | ||
from niworkflows.nipype.utils.filemanip import split_filename | ||
from niworkflows.nipype.pipeline import engine as pe | ||
from niworkflows.nipype.interfaces import ants, afni, c3, fsl | ||
from niworkflows.nipype.interfaces import ants, afni, fsl | ||
from niworkflows.nipype.interfaces import utility as niu | ||
from niworkflows.nipype.interfaces import freesurfer as fs | ||
|
||
|
@@ -173,7 +173,7 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer, | |
FreeSurfer SUBJECTS_DIR | ||
subject_id | ||
FreeSurfer subject ID | ||
fs_2_t1_transform | ||
t1_2_fsnative_reverse_transform | ||
Affine transform from FreeSurfer subject space to T1w space | ||
|
||
|
||
|
@@ -245,7 +245,7 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer, | |
inputnode = pe.Node(niu.IdentityInterface( | ||
fields=['bold_file', 't1_preproc', 't1_brain', 't1_mask', 't1_seg', 't1_tpms', | ||
't1_2_mni_forward_transform', 't1_2_mni_reverse_transform', | ||
'subjects_dir', 'subject_id', 'fs_2_t1_transform']), | ||
'subjects_dir', 'subject_id', 't1_2_fsnative_reverse_transform']), | ||
name='inputnode') | ||
inputnode.inputs.bold_file = bold_file | ||
|
||
|
@@ -320,16 +320,17 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer, | |
(inputnode, bold_reference_wf, [('bold_file', 'inputnode.bold_file')]), | ||
(bold_reference_wf, bold_hmc_wf, [ | ||
('outputnode.raw_ref_image', 'inputnode.raw_ref_image')]), | ||
(inputnode, bold_reg_wf, [('bold_file', 'inputnode.name_source'), | ||
('t1_preproc', 'inputnode.t1_preproc'), | ||
('t1_brain', 'inputnode.t1_brain'), | ||
('t1_mask', 'inputnode.t1_mask'), | ||
('t1_seg', 'inputnode.t1_seg'), | ||
# Undefined if --no-freesurfer, but this is safe | ||
('subjects_dir', 'inputnode.subjects_dir'), | ||
('subject_id', 'inputnode.subject_id'), | ||
('fs_2_t1_transform', 'inputnode.fs_2_t1_transform') | ||
]), | ||
(inputnode, bold_reg_wf, [ | ||
('bold_file', 'inputnode.name_source'), | ||
('t1_preproc', 'inputnode.t1_preproc'), | ||
('t1_brain', 'inputnode.t1_brain'), | ||
('t1_mask', 'inputnode.t1_mask'), | ||
('t1_seg', 'inputnode.t1_seg'), | ||
# Undefined if --no-freesurfer, but this is safe | ||
('subjects_dir', 'inputnode.subjects_dir'), | ||
('subject_id', 'inputnode.subject_id'), | ||
('t1_2_fsnative_reverse_transform', 'inputnode.t1_2_fsnative_reverse_transform') | ||
]), | ||
(inputnode, bold_confounds_wf, [('t1_tpms', 'inputnode.t1_tpms'), | ||
('t1_mask', 'inputnode.t1_mask')]), | ||
(bold_hmc_wf, bold_reg_wf, [('outputnode.bold_split', 'inputnode.bold_split'), | ||
|
@@ -859,17 +860,13 @@ def init_bold_reg_wf(freesurfer, bold2t1w_dof, bold_file_size_gb, omp_nthreads, | |
FreeSurfer SUBJECTS_DIR | ||
subject_id | ||
FreeSurfer subject ID | ||
fs_2_t1_transform | ||
t1_2_fsnative_reverse_transform | ||
Affine transform from FreeSurfer subject space to T1w space | ||
fieldwarp | ||
a :abbr:`DFM (displacements field map)` in ITK format | ||
|
||
Outputs | ||
|
||
mat_bold_to_t1 | ||
Affine transform from ``ref_bold_brain`` to T1 space (FSL format) | ||
mat_t1_to_bold | ||
Affine transform from T1 space to BOLD space (FSL format) | ||
itk_bold_to_t1 | ||
Affine transform from ``ref_bold_brain`` to T1 space (ITK format) | ||
itk_t1_to_bold | ||
|
@@ -878,25 +875,22 @@ def init_bold_reg_wf(freesurfer, bold2t1w_dof, bold_file_size_gb, omp_nthreads, | |
Motion-corrected BOLD series in T1 space | ||
bold_mask_t1 | ||
BOLD mask in T1 space | ||
fs_reg_file | ||
Affine transform from ``ref_bold_brain`` to T1 space (FreeSurfer ``reg`` format) | ||
out_report | ||
Reportlet visualizing quality of registration | ||
|
||
""" | ||
workflow = pe.Workflow(name=name) | ||
inputnode = pe.Node( | ||
niu.IdentityInterface(fields=['name_source', 'ref_bold_brain', 'ref_bold_mask', | ||
't1_preproc', 't1_brain', 't1_mask', | ||
't1_seg', 'bold_split', 'hmc_xforms', | ||
'subjects_dir', 'subject_id', 'fs_2_t1_transform', | ||
'fieldwarp']), | ||
niu.IdentityInterface( | ||
fields=['name_source', 'ref_bold_brain', 'ref_bold_mask', | ||
't1_preproc', 't1_brain', 't1_mask', | ||
't1_seg', 'bold_split', 'hmc_xforms', | ||
'subjects_dir', 'subject_id', 't1_2_fsnative_reverse_transform', 'fieldwarp']), | ||
name='inputnode' | ||
) | ||
outputnode = pe.Node( | ||
niu.IdentityInterface(fields=['mat_bold_to_t1', 'mat_t1_to_bold', | ||
'itk_bold_to_t1', 'itk_t1_to_bold', | ||
'bold_t1', 'bold_mask_t1', 'fs_reg_file', | ||
niu.IdentityInterface(fields=['itk_bold_to_t1', 'itk_t1_to_bold', | ||
'bold_t1', 'bold_mask_t1', | ||
'out_report']), | ||
name='outputnode' | ||
) | ||
|
@@ -906,37 +900,17 @@ def init_bold_reg_wf(freesurfer, bold2t1w_dof, bold_file_size_gb, omp_nthreads, | |
else: | ||
bbr_wf = init_fsl_bbr_wf(bold2t1w_dof, report=True) | ||
|
||
# make equivalent warp fields | ||
invt_bbr = pe.Node(fsl.ConvertXFM(invert_xfm=True), name='invt_bbr', | ||
mem_gb=DEFAULT_MEMORY_MIN_GB) | ||
|
||
# BOLD to T1 transform matrix is from fsl, using c3 tools to convert to | ||
# something ANTs will like. | ||
fsl2itk_fwd = pe.Node(c3.C3dAffineTool(fsl2ras=True, itk_transform=True), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great, I was about to propose this change. This is to move c3d into the actual (bbregister or BBR) registration algorithm pipeline, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. c3d is being used in the FLIRT-BBR workflow to translate from FSL to ITK. lta_convert is being used in the bbregister workflow to translate from LTA to ITK. LTA is FreeSurfer's format, and there's no real need to spend time in FSL's space. |
||
name='fsl2itk_fwd', mem_gb=DEFAULT_MEMORY_MIN_GB) | ||
fsl2itk_inv = pe.Node(c3.C3dAffineTool(fsl2ras=True, itk_transform=True), | ||
name='fsl2itk_inv', mem_gb=DEFAULT_MEMORY_MIN_GB) | ||
|
||
workflow.connect([ | ||
(inputnode, bbr_wf, [('ref_bold_brain', 'inputnode.in_file'), | ||
('fs_2_t1_transform', 'inputnode.fs_2_t1_transform'), | ||
('subjects_dir', 'inputnode.subjects_dir'), | ||
('subject_id', 'inputnode.subject_id'), | ||
('t1_seg', 'inputnode.t1_seg'), | ||
('t1_brain', 'inputnode.t1_brain')]), | ||
(inputnode, fsl2itk_fwd, [('t1_preproc', 'reference_file'), | ||
('ref_bold_brain', 'source_file')]), | ||
(inputnode, fsl2itk_inv, [('ref_bold_brain', 'reference_file'), | ||
('t1_preproc', 'source_file')]), | ||
(bbr_wf, invt_bbr, [('outputnode.out_matrix_file', 'in_file')]), | ||
(bbr_wf, fsl2itk_fwd, [('outputnode.out_matrix_file', 'transform_file')]), | ||
(invt_bbr, fsl2itk_inv, [('out_file', 'transform_file')]), | ||
(bbr_wf, outputnode, [('outputnode.out_matrix_file', 'mat_bold_to_t1'), | ||
('outputnode.out_reg_file', 'fs_reg_file'), | ||
(inputnode, bbr_wf, [ | ||
('ref_bold_brain', 'inputnode.in_file'), | ||
('t1_2_fsnative_reverse_transform', 'inputnode.t1_2_fsnative_reverse_transform'), | ||
('subjects_dir', 'inputnode.subjects_dir'), | ||
('subject_id', 'inputnode.subject_id'), | ||
('t1_seg', 'inputnode.t1_seg'), | ||
('t1_brain', 'inputnode.t1_brain')]), | ||
(bbr_wf, outputnode, [('outputnode.itk_bold_to_t1', 'itk_bold_to_t1'), | ||
('outputnode.itk_t1_to_bold', 'itk_t1_to_bold'), | ||
('outputnode.out_report', 'out_report')]), | ||
(invt_bbr, outputnode, [('out_file', 'mat_t1_to_bold')]), | ||
(fsl2itk_fwd, outputnode, [('itk_transform', 'itk_bold_to_t1')]), | ||
(fsl2itk_inv, outputnode, [('itk_transform', 'itk_t1_to_bold')]), | ||
]) | ||
|
||
gen_ref = pe.Node(GenerateSamplingReference(), name='gen_ref', | ||
|
@@ -952,7 +926,7 @@ def init_bold_reg_wf(freesurfer, bold2t1w_dof, bold_file_size_gb, omp_nthreads, | |
(inputnode, gen_ref, [('ref_bold_brain', 'moving_image'), | ||
('t1_brain', 'fixed_image')]), | ||
(gen_ref, mask_t1w_tfm, [('out_file', 'reference_image')]), | ||
(fsl2itk_fwd, mask_t1w_tfm, [('itk_transform', 'transforms')]), | ||
(bbr_wf, mask_t1w_tfm, [('outputnode.itk_bold_to_t1', 'transforms')]), | ||
(inputnode, mask_t1w_tfm, [('ref_bold_mask', 'input_image')]), | ||
(mask_t1w_tfm, outputnode, [('output_image', 'bold_mask_t1')]) | ||
]) | ||
|
@@ -977,7 +951,7 @@ def init_bold_reg_wf(freesurfer, bold2t1w_dof, bold_file_size_gb, omp_nthreads, | |
merge = pe.Node(Merge(compress=use_compression), name='merge', mem_gb=bold_file_size_gb * 3) | ||
|
||
workflow.connect([ | ||
(fsl2itk_fwd, merge_xforms, [('itk_transform', 'in1')]), | ||
(bbr_wf, merge_xforms, [('outputnode.itk_bold_to_t1', 'in1')]), | ||
(merge_xforms, bold_to_t1w_transform, [('out', 'transforms')]), | ||
(inputnode, merge, [('name_source', 'header_source')]), | ||
(merge, outputnode, [('out_file', 'bold_t1')]), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would imagine that we don't need FSL transforms because we are not chaining them? (we resample in T1 space, I assume). Is this correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answered below, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm doing this right now because nipype doesn't have LTA outputs from tkregister enabled. See nipy/nipype#2217. (Though it also doesn't matter in the long run, since we drop tkregister in #733.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh. Actually just realized I'm missing two inputs to
fsl2lta
. Hold off on merging.