Skip to content

Commit fef5aa8

Browse files
authored
Merge pull request #437 from mgxd/fix/anat-coreg
ENH: Output anatomical coregistration transforms, if generated
2 parents a95c8bd + 1edb875 commit fef5aa8

File tree

6 files changed

+61
-94
lines changed

6 files changed

+61
-94
lines changed

.circleci/bcp_anat_outputs.txt

+2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_desc-preproc_T2w.json
1616
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_desc-preproc_T2w.nii.gz
1717
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-MNIInfant+1_to-T1w_mode-image_xfm.h5
1818
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-T1w_to-MNIInfant+1_mode-image_xfm.h5
19+
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-T1w_to-T2w_mode-image_xfm.h5
1920
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-T1w_to-fsnative_mode-image_xfm.txt
21+
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-T2w_to-T1w_mode-image_xfm.h5
2022
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-fsnative_to-T1w_mode-image_xfm.txt
2123
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_hemi-L_curv.shape.gii
2224
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_hemi-L_inflated.surf.gii

.circleci/bcp_full_outputs.txt

+2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_desc-preproc_T2w.json
1616
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_desc-preproc_T2w.nii.gz
1717
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-MNIInfant+1_to-T1w_mode-image_xfm.h5
1818
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-T1w_to-MNIInfant+1_mode-image_xfm.h5
19+
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-T1w_to-T2w_mode-image_xfm.h5
1920
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-T1w_to-fsnative_mode-image_xfm.txt
21+
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-T2w_to-T1w_mode-image_xfm.h5
2022
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_from-fsnative_to-T1w_mode-image_xfm.txt
2123
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_hemi-L_curv.shape.gii
2224
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_hemi-L_inflated.surf.gii

nibabies/data/within_subject_t1t2.json nibabies/data/t1-t2-coreg.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
[ 0.1, 3.0, 0.0 ]
3232
],
3333
"transforms": [ "Translation", "Rigid", "SyN" ],
34-
"use_histogram_matching": [ true, true, true ],
34+
"use_histogram_matching": false,
3535
"verbose": true,
3636
"winsorize_lower_quantile": 0.0001,
3737
"winsorize_upper_quantile": 0.9999,
38-
"write_composite_transform": false
38+
"write_composite_transform": true
3939
}

nibabies/data/t1_to_bold.json

-40
This file was deleted.

nibabies/workflows/anatomical/fit.py

+47-43
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
)
3636

3737
from nibabies import config
38+
from nibabies.interfaces import DerivativesDataSink
3839
from nibabies.workflows.anatomical.brain_extraction import init_infant_brain_extraction_wf
39-
from nibabies.workflows.anatomical.outputs import init_anat_reports_wf
40+
from nibabies.workflows.anatomical.outputs import init_anat_reports_wf, init_coreg_report_wf
4041
from nibabies.workflows.anatomical.preproc import init_anat_preproc_wf, init_csf_norm_wf
4142
from nibabies.workflows.anatomical.registration import (
4243
init_concat_registrations_wf,
@@ -741,36 +742,33 @@ def init_infant_anat_fit_wf(
741742
probmap=probmap,
742743
)
743744

744-
# TODO: Currently the XFMs are transform0GenericAffine.mat, transform1Warp.nii.gz
745-
# The coregistration should be changed to instead save
746-
# 'composite_transform' and 'inverse_composite_transform'
747-
# from antsRegistration (single h5 files)
748-
#
749-
# ds_t1w2t2w_xfm = pe.Node(
750-
# DerivativesDataSink(
751-
# base_directory=output_dir,
752-
# to='T2w',
753-
# mode='image',
754-
# suffix='xfm',
755-
# dismiss_entites=('desc', 'echo'),
756-
# **{'from': 'T1w'}
757-
# ),
758-
# name='ds_t1w2t2w_xfm',
759-
# run_without_submitting=True,
760-
# )
761-
762-
# ds_t2w2t1w_xfm = pe.Node(
763-
# DerivativesDataSink(
764-
# base_directory=output_dir,
765-
# to='T1w',
766-
# mode='image',
767-
# suffix='xfm',
768-
# dismiss_entites=('desc', 'echo'),
769-
# **{'from': 'T2w'}
770-
# ),
771-
# name='ds_t2w2t1w_xfm',
772-
# run_without_submitting=True,
773-
# )
745+
ds_t1w2t2w_xfm = pe.Node(
746+
DerivativesDataSink(
747+
base_directory=output_dir,
748+
to='T2w',
749+
mode='image',
750+
suffix='xfm',
751+
dismiss_entities=('desc', 'echo'),
752+
**{'from': 'T1w'},
753+
),
754+
name='ds_t1w2t2w_xfm',
755+
run_without_submitting=True,
756+
)
757+
758+
ds_t2w2t1w_xfm = pe.Node(
759+
DerivativesDataSink(
760+
base_directory=output_dir,
761+
to='T1w',
762+
mode='image',
763+
suffix='xfm',
764+
dismiss_entities=('desc', 'echo'),
765+
**{'from': 'T2w'},
766+
),
767+
name='ds_t2w2t1w_xfm',
768+
run_without_submitting=True,
769+
)
770+
771+
coreg_report_wf = init_coreg_report_wf(output_dir=output_dir)
774772

775773
workflow.connect([
776774
(t1w_validate, coregistration_wf, [
@@ -780,22 +778,28 @@ def init_infant_anat_fit_wf(
780778
('t2w_preproc', 'inputnode.in_t2w'),
781779
('t2w_mask', 'inputnode.in_mask'),
782780
]),
783-
# (coregistration_wf, ds_t1w2t2w_xfm, [
784-
# ('outputnode.t1w2t2w_xfm', 'in_file'),
785-
# ]),
786-
# (sourcefile_buffer, ds_t1w2t2w_xfm, [
787-
# ('t1w_source_files', 'source_file'),
788-
# ]),
789-
# (coregistration_wf, ds_t2w2t1w_xfm, [
790-
# ('outputnode.t2w2t1w_xfm', 'in_file'),
791-
# ]),
792-
# (sourcefile_buffer, ds_t2w2t1w_xfm, [
793-
# ('t2w_source_files', 'source_file'),
794-
# ]),
781+
(coregistration_wf, ds_t1w2t2w_xfm, [
782+
('outputnode.t1w2t2w_xfm', 'in_file'),
783+
]),
784+
(sourcefile_buffer, ds_t1w2t2w_xfm, [
785+
('t1w_source_files', 'source_file'),
786+
]),
787+
(coregistration_wf, ds_t2w2t1w_xfm, [
788+
('outputnode.t2w2t1w_xfm', 'in_file'),
789+
]),
790+
(sourcefile_buffer, ds_t2w2t1w_xfm, [
791+
('t2w_source_files', 'source_file'),
792+
]),
795793
(coregistration_wf, coreg_buffer, [
796794
('outputnode.t1w2t2w_xfm', 't1w2t2w_xfm'),
797795
('outputnode.t2w2t1w_xfm', 't2w2t1w_xfm'),
798796
]),
797+
(coregistration_wf, coreg_report_wf, [
798+
('outputnode.t1w_preproc', 'inputnode.t1w_preproc'),
799+
('outputnode.t2w_preproc', 'inputnode.t2w_preproc'),
800+
('outputnode.t1w_mask', 'inputnode.in_mask'),
801+
]),
802+
(sourcefile_buffer, coreg_report_wf, [('anat_source_files', 'inputnode.source_file')]),
799803
]) # fmt:skip
800804

801805
if probmap:

nibabies/workflows/anatomical/registration.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def init_coregistration_wf(
134134

135135
# Set up T1w -> T2w within-subject registration
136136
coreg = pe.Node(
137-
Registration(from_file=get_file('nibabies', 'data/within_subject_t1t2.json')),
137+
Registration(from_file=get_file('nibabies', 'data/t1-t2-coreg.json')),
138138
name='coreg',
139139
n_procs=omp_nthreads,
140140
mem_gb=mem_gb,
@@ -177,15 +177,14 @@ def init_coregistration_wf(
177177
('in_t2w', 'input_image')]),
178178
(fixed_masks_arg, coreg, [('out', 'fixed_image_masks')]),
179179
(coreg, map_t2w, [
180-
('reverse_transforms', 'transforms'),
181-
('reverse_invert_flags', 'invert_transform_flags'),
180+
('inverse_composite_transform', 'transforms'),
182181
]),
183182
(final_n4, apply_mask, [('output_image', 'in_file')]),
184183
(final_n4, outputnode, [('output_image', 't1w_preproc')]),
185184
(map_t2w, outputnode, [('output_image', 't2w_preproc')]),
186185
(apply_mask, outputnode, [('out_file', 't1w_brain')]),
187-
(coreg, outputnode, [('forward_transforms', 't1w2t2w_xfm')]),
188-
(coreg, outputnode, [('reverse_transforms', 't2w2t1w_xfm')]),
186+
(coreg, outputnode, [('composite_transform', 't1w2t2w_xfm')]),
187+
(coreg, outputnode, [('inverse_composite_transform', 't2w2t1w_xfm')]),
189188
])
190189
# fmt: on
191190

@@ -218,8 +217,8 @@ def init_coregistration_wf(
218217
('in_t1w', 'reference_image'),
219218
('in_probmap', 'input_image')]),
220219
(coreg, map_mask, [
221-
('reverse_transforms', 'transforms'),
222-
('reverse_invert_flags', 'invert_transform_flags')]),
220+
('inverse_composite_transform', 'transforms'),
221+
]),
223222
(map_mask, thr_mask, [('output_image', 'in_file')]),
224223
(map_mask, final_n4, [('output_image', 'weight_image')]),
225224
(thr_mask, outputnode, [('out_mask', 't1w_mask')]),
@@ -240,8 +239,8 @@ def init_coregistration_wf(
240239
('in_t1w', 'reference_image'),
241240
('in_mask', 'input_image')]),
242241
(coreg, map_precomp_mask, [
243-
('reverse_transforms', 'transforms'),
244-
('reverse_invert_flags', 'invert_transform_flags')]),
242+
('inverse_composite_transform', 'transforms'),
243+
]),
245244
(map_precomp_mask, final_n4, [('output_image', 'weight_image')]),
246245
(map_precomp_mask, outputnode, [('output_image', 't1w_mask')]),
247246
(map_precomp_mask, apply_mask, [('output_image', 'in_mask')]),

0 commit comments

Comments
 (0)