Skip to content

Commit 734c4a4

Browse files
authored
FIX: Relabel sub-structures before discarding (#186)
* FIX: Relabel sub-structures before discarding Addresses problem raised in #149 Initial implementation using a custom `Function`, but this may be worth a proper interface. * TST: Add test for new interface * ENH: Add interface for label remapping * ENH: Incoporate new interface into CIFTI workflow * FIX: Coerce values to integers * ENH: Upgrade to `niworkflows` 1.5.x Since nibabel interfaces have been ported over, they can be removed from this codebase. * PIN: Latest sdcflows
1 parent be1e869 commit 734c4a4

File tree

7 files changed

+40
-240
lines changed

7 files changed

+40
-240
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"173": 16,
3+
"174": 16,
4+
"175": 16,
5+
6+
"500": 53,
7+
"501": 53,
8+
"502": 53,
9+
"503": 53,
10+
"504": 53,
11+
"505": 53,
12+
"506": 53,
13+
"507": 53,
14+
"508": 53,
15+
16+
"550": 17,
17+
"551": 17,
18+
"552": 17,
19+
"553": 17,
20+
"554": 17,
21+
"555": 17,
22+
"556": 17,
23+
"557": 17,
24+
"558": 17
25+
}

nibabies/interfaces/nibabel.py

Lines changed: 0 additions & 115 deletions
This file was deleted.

nibabies/interfaces/tests/test_nibabel.py

Lines changed: 0 additions & 73 deletions
This file was deleted.

nibabies/workflows/anatomical/brain_extraction.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,13 @@ def init_infant_brain_extraction_wf(
8080
from nipype.interfaces.ants import N4BiasFieldCorrection, ImageMath
8181

8282
# niworkflows
83-
from niworkflows.interfaces.nibabel import ApplyMask, Binarize, IntensityClip
83+
from niworkflows.interfaces.nibabel import ApplyMask, Binarize, IntensityClip, BinaryDilation
8484
from niworkflows.interfaces.fixes import (
8585
FixHeaderRegistration as Registration,
8686
FixHeaderApplyTransforms as ApplyTransforms,
8787
)
8888
from templateflow.api import get as get_template
8989

90-
from ...interfaces.nibabel import BinaryDilation
9190
from ...utils.misc import cohort_by_months
9291

9392
# handle template specifics

nibabies/workflows/anatomical/registration.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ def init_coregistration_wf(
8181
FixHeaderRegistration as Registration,
8282
FixHeaderApplyTransforms as ApplyTransforms,
8383
)
84-
from niworkflows.interfaces.nibabel import ApplyMask, Binarize
85-
from ...interfaces.nibabel import BinaryDilation
84+
from niworkflows.interfaces.nibabel import ApplyMask, Binarize, BinaryDilation
8685

8786
workflow = pe.Workflow(name)
8887

nibabies/workflows/bold/alignment.py

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def init_subcortical_rois_wf(*, name="subcortical_rois_wf"):
3434
Subcortical ROIs in `MNI152NLin6Asym` space
3535
"""
3636
from templateflow.api import get as get_template
37+
from niworkflows.interfaces.nibabel import MapLabels
3738

3839
# TODO: Implement BOLD refinement once InfantFS outputs subj/mri/wmparc.mgz
3940
# The code is found at
@@ -68,6 +69,13 @@ def init_subcortical_rois_wf(*, name="subcortical_rois_wf"):
6869
# name="applywarp_std"
6970
# )
7071

72+
map_labels = pe.Node(
73+
MapLabels(
74+
mappings_file=resource_filename("nibabies", "data/FreeSurferLabelRemappings.json")
75+
),
76+
name='map_labels',
77+
)
78+
7179
subcortical_labels = resource_filename(
7280
"nibabies", "data/FreeSurferSubcorticalLabelTableLut.txt"
7381
)
@@ -78,7 +86,8 @@ def init_subcortical_rois_wf(*, name="subcortical_rois_wf"):
7886

7987
# fmt: off
8088
workflow.connect([
81-
(inputnode, refine_bold_rois, [("MNIInfant_aseg", "in_file")]),
89+
(inputnode, map_labels, [("MNIInfant_aseg", "in_file")]),
90+
(map_labels, refine_bold_rois, [("out_file", "in_file")]),
8291
# (applywarp_tpl, refine_std_rois, [("out_file", "in_file")]),
8392
(refine_bold_rois, outputnode, [("out_file", "MNIInfant_rois")]),
8493
])
@@ -119,7 +128,7 @@ def init_subcortical_mni_alignment_wf(*, vol_sigma=0.8, name="subcortical_mni_al
119128
Volume file containing all labels
120129
"""
121130
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
122-
from ...interfaces.nibabel import MergeROIs
131+
from niworkflows.interfaces.nibabel import MergeROIs
123132
from ...interfaces.workbench import (
124133
CiftiCreateDenseTimeseries,
125134
CiftiCreateLabel,
@@ -350,47 +359,3 @@ def format_agg_rois(rois):
350359
351360
"""
352361
return rois[0], rois[1:], ("-add %s " * (len(rois) - 1)).strip()
353-
354-
355-
def drop_labels(in_file):
356-
"""Drop non-subcortical labels"""
357-
from pathlib import Path
358-
import nibabel as nb
359-
import numpy as np
360-
from niworkflows.interfaces.cifti import _reorient_image
361-
362-
# FreeSurfer LUT values
363-
expected_labels = {
364-
8,
365-
10,
366-
11,
367-
12,
368-
13,
369-
16,
370-
17,
371-
18,
372-
26,
373-
28,
374-
47,
375-
49,
376-
50,
377-
51,
378-
52,
379-
53,
380-
54,
381-
58,
382-
60,
383-
}
384-
img = _reorient_image(nb.load(in_file), orientation="LAS")
385-
hdr = img.header
386-
data = np.asanyarray(img.dataobj).astype("int16")
387-
hdr.set_data_dtype("int16")
388-
labels = np.unique(data)
389-
390-
for label in labels:
391-
if label not in expected_labels:
392-
data[data == label] = 0
393-
394-
out_file = str(Path("ROIs.nii.gz").absolute())
395-
img.__class__(data, img.affine, header=hdr).to_filename(out_file)
396-
return out_file

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ install_requires =
2424
nibabel >= 3.0.1
2525
nipype >= 1.5.1
2626
nitime
27-
niworkflows ~= 1.4.0
27+
niworkflows ~= 1.5.0
2828
numpy >= 1.16.5
2929
pybids >= 0.12.1
30-
sdcflows ~= 2.0.7
30+
sdcflows ~= 2.0.12
3131
smriprep ~= 0.8.1
3232
templateflow >= 0.6.0
3333
test_requires =

0 commit comments

Comments
 (0)