Skip to content

Commit 4dc12c5

Browse files
committed
RF: Clean up segmentation workflow
- Precomputed aseg should be connected via the inputnode, no need to validate the image again. - MCRIBS code will be moved to the MCRIBS-specific surface workflow
1 parent 7e80006 commit 4dc12c5

File tree

1 file changed

+6
-52
lines changed

1 file changed

+6
-52
lines changed

nibabies/workflows/anatomical/segmentation.py

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ def init_anat_segmentations_wf(
5252
name="inputnode",
5353
)
5454
outputnode = pe.Node(
55-
niu.IdentityInterface(fields=["anat_aseg", "anat_mcrib_aseg", "anat_dseg", "anat_tpms"]),
55+
niu.IdentityInterface(fields=["anat_aseg", "anat_dseg", "anat_tpms"]),
5656
name="outputnode",
5757
)
58+
buffernode = niu.IdentityInterface(fields=["final_aseg"], name='buffernode')
5859

5960
wf.__desc__ = """Brain tissue segmentation of cerebrospinal fluid (CSF),
6061
white-matter (WM) and gray-matter (GM) was performed on """
@@ -160,74 +161,27 @@ def init_anat_segmentations_wf(
160161
(apply_atlas, jointfusion, [('output_image', 'atlas_image')]),
161162
(apply_seg, jointfusion, [('output_image', 'atlas_segmentation_image')]),
162163
(jointfusion, jf_label, [('out_label_fusion', 'in_file')]),
164+
(jf_label, buffernode, [('out_file', 'final_aseg')]),
163165
])
164166
# fmt:on
165167

166168
elif precomp_aseg:
167169
wf.__desc__ += "a pre-computed segmentation."
168-
from niworkflows.interfaces.header import ValidateImage
169170

170-
inputnode.inputs.anat_aseg = precomp_aseg
171-
validate_aseg = pe.Node(ValidateImage(), name="validate_aseg")
172-
wf.connect(inputnode, "anat_aseg", validate_aseg, "in_file")
171+
wf.connect(inputnode, "anat_aseg", buffernode, "final_aseg")
173172

174173
# Otherwise, the final aseg will be split into three tissue classes
175174
# regardless if it was precomputed or generated via JLF
176175
lut_anat_dseg.inputs.lut = _aseg_to_three()
177176
split_seg = pe.Node(niu.Function(function=_split_segments), name="split_seg")
178-
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")
221177

222178
# fmt: off
223179
wf.connect([
224-
(out_aseg, outputnode, [('out_file', 'anat_aseg')]),
225-
(out_aseg, lut_anat_dseg, [('out_file', 'in_dseg')]),
180+
(buffernode, outputnode, [('final_aseg', 'anat_aseg')]),
181+
(buffernode, lut_anat_dseg, [('final_aseg', 'in_dseg')]),
226182
(lut_anat_dseg, outputnode, [('out', 'anat_dseg')]),
227183
(lut_anat_dseg, split_seg, [('out', 'in_file')]),
228184
(split_seg, outputnode, [('out', 'anat_tpms')]),
229-
(out_aseg, map_labels, [("out_file", "in_file")]),
230-
(map_labels, outputnode, [("out_file", "anat_mcrib_aseg")]),
231185
])
232186
# fmt: on
233187

0 commit comments

Comments
 (0)