Skip to content

Commit 172a3e7

Browse files
madisothmgxd
andcommitted
Remap labels from FreeSurfer aseg to MCRIB (#270)
* use MapLabel interface to remap aseg labels to mcrib-compatible * STY: black * Update nibabies/workflows/anatomical/segmentation.py Co-authored-by: Mathias Goncalves <[email protected]> * Update nibabies/workflows/anatomical/segmentation.py Co-authored-by: Mathias Goncalves <[email protected]> * Update segmentation.py add suggestions from PR review * Update segmentation.py formatting * Update segmentation.py define aseg2mcrib dict before using Co-authored-by: Mathias Goncalves <[email protected]>
1 parent c150420 commit 172a3e7

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

nibabies/workflows/anatomical/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def init_infant_anat_wf(
147147
"surfaces",
148148
"morphometrics",
149149
"anat_aseg",
150+
"anat_mcrib",
150151
"anat_aparc",
151152
"template",
152153
]

nibabies/workflows/anatomical/segmentation.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from nipype.pipeline import engine as pe
77
from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms
88
from niworkflows.interfaces.fixes import FixHeaderRegistration as Registration
9+
from niworkflows.interfaces.nibabel import MapLabels
910
from pkg_resources import resource_filename as pkgr_fn
1011
from smriprep.utils.misc import apply_lut as _apply_bids_lut
1112
from smriprep.workflows.anatomical import (
@@ -51,7 +52,7 @@ def init_anat_segmentations_wf(
5152
name="inputnode",
5253
)
5354
outputnode = pe.Node(
54-
niu.IdentityInterface(fields=["anat_aseg", "anat_dseg", "anat_tpms"]),
55+
niu.IdentityInterface(fields=["anat_aseg", "anat_mcrib_aseg", "anat_dseg", "anat_tpms"]),
5556
name="outputnode",
5657
)
5758

@@ -175,15 +176,61 @@ def init_anat_segmentations_wf(
175176
lut_anat_dseg.inputs.lut = _aseg_to_three()
176177
split_seg = pe.Node(niu.Function(function=_split_segments), name="split_seg")
177178
out_aseg = validate_aseg if precomp_aseg else jf_label
179+
180+
wf.__desc__ += """Segmentation volume label indices were remapped
181+
from FreeSurfer to M-CRIB-compatible format. """
182+
183+
# dictionary to map labels from aseg to mcrib
184+
aseg2mcrib = {
185+
2: 51,
186+
3: 21,
187+
4: 49,
188+
5: 0,
189+
7: 17,
190+
8: 17,
191+
10: 43,
192+
11: 41,
193+
12: 47,
194+
13: 47,
195+
14: 0,
196+
15: 0,
197+
16: 19,
198+
17: 1,
199+
18: 3,
200+
26: 41,
201+
28: 45,
202+
31: 49,
203+
41: 52,
204+
42: 20,
205+
43: 50,
206+
44: 0,
207+
46: 18,
208+
47: 18,
209+
49: 42,
210+
50: 40,
211+
51: 46,
212+
52: 46,
213+
53: 2,
214+
54: 4,
215+
58: 40,
216+
60: 44,
217+
63: 50,
218+
253: 48,
219+
}
220+
map_labels = pe.Node(MapLabels(mappings=aseg2mcrib), name="map_labels")
221+
178222
# fmt: off
179223
wf.connect([
180224
(out_aseg, outputnode, [('out_file', 'anat_aseg')]),
181225
(out_aseg, lut_anat_dseg, [('out_file', 'in_dseg')]),
182226
(lut_anat_dseg, outputnode, [('out', 'anat_dseg')]),
183227
(lut_anat_dseg, split_seg, [('out', 'in_file')]),
184228
(split_seg, outputnode, [('out', 'anat_tpms')]),
229+
(out_aseg, map_labels, [("out_file", "in_file")]),
230+
(map_labels, outputnode, [("out_file", "anat_mcrib_aseg")]),
185231
])
186232
# fmt: on
233+
187234
return wf
188235

189236

0 commit comments

Comments
 (0)