Skip to content

Commit 014b17a

Browse files
kaitjnx10
authored andcommitted
Save normalized t1w brain
1 parent fee885b commit 014b17a

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/rbc/core/anatomical/registration.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@
2121
_PREFIX = "ants_reg"
2222

2323

24-
class CompositeTransforms(NamedTuple):
25-
"""Forward and inverse composite transformation paths."""
24+
class RegistrationOutputs(NamedTuple):
25+
"""Outputs from ANTs registration to a standard-space template.
2626
27+
Attributes:
28+
brain: Warped (template-space) skull-stripped brain.
29+
forward: T1w-to-template composite displacement field.
30+
inverse: Template-to-T1w composite displacement field.
31+
"""
32+
33+
brain: Path
2734
forward: Path
2835
inverse: Path
2936

@@ -32,7 +39,7 @@ def ants_registration(
3239
in_file: Path,
3340
seed: int = CPAC_ANTS_SEED,
3441
registration_template: Path = REGISTRATION_TEMPLATES.brain_1mm,
35-
) -> CompositeTransforms:
42+
) -> RegistrationOutputs:
3643
"""Register a skull-stripped T1w to a standard-space template with ANTs.
3744
3845
Runs a three-stage registration (Rigid -> Affine -> SyN) and then
@@ -171,6 +178,10 @@ def ants_registration(
171178
print_out_composite_warp_file=True,
172179
),
173180
)
174-
return CompositeTransforms(
175-
forward=fwd.output.output_image_outfile, inverse=rev.output.output_image_outfile
181+
# ANTs writes the warped image to {prefix}_Warped.nii.gz but NiWrap
182+
# does not expose this path, so we construct it from the output root.
183+
return RegistrationOutputs(
184+
brain=registration.root / f"{_PREFIX}_Warped.nii.gz",
185+
forward=fwd.output.output_image_outfile,
186+
inverse=rev.output.output_image_outfile,
176187
)

src/rbc/workflows/anatomical.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class AnatomicalOutputs(NamedTuple):
3838
Attributes:
3939
brain: Skull-stripped T1w brain.
4040
brain_mask: Binary brain mask.
41+
brain_tpl: Skull-stripped T1w brain in template space.
4142
csf_mask: CSF tissue mask.
4243
gm_mask: GM tissue mask.
4344
wm_mask: WM tissue mask.
@@ -48,6 +49,7 @@ class AnatomicalOutputs(NamedTuple):
4849

4950
brain: Path
5051
brain_mask: Path
52+
brain_tpl: Path
5153
csf_mask: Path
5254
gm_mask: Path
5355
wm_mask: Path
@@ -105,6 +107,7 @@ def single_session_preprocess(
105107
return AnatomicalOutputs(
106108
brain=extracted_t1w.brain,
107109
brain_mask=extracted_t1w.brain_mask,
110+
brain_tpl=transforms.brain,
108111
csf_mask=tissue_masks.csf,
109112
gm_mask=tissue_masks.gm,
110113
wm_mask=tissue_masks.wm,

0 commit comments

Comments
 (0)