Skip to content

Commit

Permalink
Merge pull request #437 from mgxd/fix/anat-coreg
Browse files Browse the repository at this point in the history
ENH: Output anatomical coregistration transforms, if generated
  • Loading branch information
mgxd authored Jan 24, 2025
2 parents a95c8bd + 1edb875 commit fef5aa8
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 94 deletions.
2 changes: 2 additions & 0 deletions .circleci/bcp_anat_outputs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_desc-preproc_T2w.json
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_desc-preproc_T2w.nii.gz
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-MNIInfant+1_to-T1w_mode-image_xfm.h5
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-T1w_to-MNIInfant+1_mode-image_xfm.h5
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-T1w_to-T2w_mode-image_xfm.h5
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-T1w_to-fsnative_mode-image_xfm.txt
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-T2w_to-T1w_mode-image_xfm.h5
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-fsnative_to-T1w_mode-image_xfm.txt
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_hemi-L_curv.shape.gii
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_hemi-L_inflated.surf.gii
Expand Down
2 changes: 2 additions & 0 deletions .circleci/bcp_full_outputs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_desc-preproc_T2w.json
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_desc-preproc_T2w.nii.gz
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-MNIInfant+1_to-T1w_mode-image_xfm.h5
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-T1w_to-MNIInfant+1_mode-image_xfm.h5
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-T1w_to-T2w_mode-image_xfm.h5
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-T1w_to-fsnative_mode-image_xfm.txt
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-T2w_to-T1w_mode-image_xfm.h5
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-fsnative_to-T1w_mode-image_xfm.txt
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_hemi-L_curv.shape.gii
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_hemi-L_inflated.surf.gii
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
[ 0.1, 3.0, 0.0 ]
],
"transforms": [ "Translation", "Rigid", "SyN" ],
"use_histogram_matching": [ true, true, true ],
"use_histogram_matching": false,
"verbose": true,
"winsorize_lower_quantile": 0.0001,
"winsorize_upper_quantile": 0.9999,
"write_composite_transform": false
"write_composite_transform": true
}
40 changes: 0 additions & 40 deletions nibabies/data/t1_to_bold.json

This file was deleted.

90 changes: 47 additions & 43 deletions nibabies/workflows/anatomical/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
)

from nibabies import config
from nibabies.interfaces import DerivativesDataSink
from nibabies.workflows.anatomical.brain_extraction import init_infant_brain_extraction_wf
from nibabies.workflows.anatomical.outputs import init_anat_reports_wf
from nibabies.workflows.anatomical.outputs import init_anat_reports_wf, init_coreg_report_wf
from nibabies.workflows.anatomical.preproc import init_anat_preproc_wf, init_csf_norm_wf
from nibabies.workflows.anatomical.registration import (
init_concat_registrations_wf,
Expand Down Expand Up @@ -741,36 +742,33 @@ def init_infant_anat_fit_wf(
probmap=probmap,
)

# TODO: Currently the XFMs are transform0GenericAffine.mat, transform1Warp.nii.gz
# The coregistration should be changed to instead save
# 'composite_transform' and 'inverse_composite_transform'
# from antsRegistration (single h5 files)
#
# ds_t1w2t2w_xfm = pe.Node(
# DerivativesDataSink(
# base_directory=output_dir,
# to='T2w',
# mode='image',
# suffix='xfm',
# dismiss_entites=('desc', 'echo'),
# **{'from': 'T1w'}
# ),
# name='ds_t1w2t2w_xfm',
# run_without_submitting=True,
# )

# ds_t2w2t1w_xfm = pe.Node(
# DerivativesDataSink(
# base_directory=output_dir,
# to='T1w',
# mode='image',
# suffix='xfm',
# dismiss_entites=('desc', 'echo'),
# **{'from': 'T2w'}
# ),
# name='ds_t2w2t1w_xfm',
# run_without_submitting=True,
# )
ds_t1w2t2w_xfm = pe.Node(
DerivativesDataSink(
base_directory=output_dir,
to='T2w',
mode='image',
suffix='xfm',
dismiss_entities=('desc', 'echo'),
**{'from': 'T1w'},
),
name='ds_t1w2t2w_xfm',
run_without_submitting=True,
)

ds_t2w2t1w_xfm = pe.Node(
DerivativesDataSink(
base_directory=output_dir,
to='T1w',
mode='image',
suffix='xfm',
dismiss_entities=('desc', 'echo'),
**{'from': 'T2w'},
),
name='ds_t2w2t1w_xfm',
run_without_submitting=True,
)

coreg_report_wf = init_coreg_report_wf(output_dir=output_dir)

workflow.connect([
(t1w_validate, coregistration_wf, [
Expand All @@ -780,22 +778,28 @@ def init_infant_anat_fit_wf(
('t2w_preproc', 'inputnode.in_t2w'),
('t2w_mask', 'inputnode.in_mask'),
]),
# (coregistration_wf, ds_t1w2t2w_xfm, [
# ('outputnode.t1w2t2w_xfm', 'in_file'),
# ]),
# (sourcefile_buffer, ds_t1w2t2w_xfm, [
# ('t1w_source_files', 'source_file'),
# ]),
# (coregistration_wf, ds_t2w2t1w_xfm, [
# ('outputnode.t2w2t1w_xfm', 'in_file'),
# ]),
# (sourcefile_buffer, ds_t2w2t1w_xfm, [
# ('t2w_source_files', 'source_file'),
# ]),
(coregistration_wf, ds_t1w2t2w_xfm, [
('outputnode.t1w2t2w_xfm', 'in_file'),
]),
(sourcefile_buffer, ds_t1w2t2w_xfm, [
('t1w_source_files', 'source_file'),
]),
(coregistration_wf, ds_t2w2t1w_xfm, [
('outputnode.t2w2t1w_xfm', 'in_file'),
]),
(sourcefile_buffer, ds_t2w2t1w_xfm, [
('t2w_source_files', 'source_file'),
]),
(coregistration_wf, coreg_buffer, [
('outputnode.t1w2t2w_xfm', 't1w2t2w_xfm'),
('outputnode.t2w2t1w_xfm', 't2w2t1w_xfm'),
]),
(coregistration_wf, coreg_report_wf, [
('outputnode.t1w_preproc', 'inputnode.t1w_preproc'),
('outputnode.t2w_preproc', 'inputnode.t2w_preproc'),
('outputnode.t1w_mask', 'inputnode.in_mask'),
]),
(sourcefile_buffer, coreg_report_wf, [('anat_source_files', 'inputnode.source_file')]),
]) # fmt:skip

if probmap:
Expand Down
17 changes: 8 additions & 9 deletions nibabies/workflows/anatomical/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def init_coregistration_wf(

# Set up T1w -> T2w within-subject registration
coreg = pe.Node(
Registration(from_file=get_file('nibabies', 'data/within_subject_t1t2.json')),
Registration(from_file=get_file('nibabies', 'data/t1-t2-coreg.json')),
name='coreg',
n_procs=omp_nthreads,
mem_gb=mem_gb,
Expand Down Expand Up @@ -177,15 +177,14 @@ def init_coregistration_wf(
('in_t2w', 'input_image')]),
(fixed_masks_arg, coreg, [('out', 'fixed_image_masks')]),
(coreg, map_t2w, [
('reverse_transforms', 'transforms'),
('reverse_invert_flags', 'invert_transform_flags'),
('inverse_composite_transform', 'transforms'),
]),
(final_n4, apply_mask, [('output_image', 'in_file')]),
(final_n4, outputnode, [('output_image', 't1w_preproc')]),
(map_t2w, outputnode, [('output_image', 't2w_preproc')]),
(apply_mask, outputnode, [('out_file', 't1w_brain')]),
(coreg, outputnode, [('forward_transforms', 't1w2t2w_xfm')]),
(coreg, outputnode, [('reverse_transforms', 't2w2t1w_xfm')]),
(coreg, outputnode, [('composite_transform', 't1w2t2w_xfm')]),
(coreg, outputnode, [('inverse_composite_transform', 't2w2t1w_xfm')]),
])
# fmt: on

Expand Down Expand Up @@ -218,8 +217,8 @@ def init_coregistration_wf(
('in_t1w', 'reference_image'),
('in_probmap', 'input_image')]),
(coreg, map_mask, [
('reverse_transforms', 'transforms'),
('reverse_invert_flags', 'invert_transform_flags')]),
('inverse_composite_transform', 'transforms'),
]),
(map_mask, thr_mask, [('output_image', 'in_file')]),
(map_mask, final_n4, [('output_image', 'weight_image')]),
(thr_mask, outputnode, [('out_mask', 't1w_mask')]),
Expand All @@ -240,8 +239,8 @@ def init_coregistration_wf(
('in_t1w', 'reference_image'),
('in_mask', 'input_image')]),
(coreg, map_precomp_mask, [
('reverse_transforms', 'transforms'),
('reverse_invert_flags', 'invert_transform_flags')]),
('inverse_composite_transform', 'transforms'),
]),
(map_precomp_mask, final_n4, [('output_image', 'weight_image')]),
(map_precomp_mask, outputnode, [('output_image', 't1w_mask')]),
(map_precomp_mask, apply_mask, [('output_image', 'in_mask')]),
Expand Down

0 comments on commit fef5aa8

Please sign in to comment.