Skip to content

Commit c0cc020

Browse files
authored
Merge pull request #689 from nipreps/fix/error-nifti-extraction
FIX: Error handling the segmentation in NIfTI extraction
2 parents 8c0b6a6 + a0480ef commit c0cc020

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

niworkflows/utils/timeseries.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def _cifti_timeseries(dataset):
5555
def _nifti_timeseries(
5656
dataset,
5757
segmentation=None,
58-
labels=("Ctx GM", "dGM", "WM+CSF", "Cb"),
58+
labels=("Ctx GM", "dGM", "WM+CSF", "Cb", "Crown"),
5959
remap_rois=True,
6060
lut=None,
6161
):
@@ -66,17 +66,20 @@ def _nifti_timeseries(
6666
if segmentation is None:
6767
return data, None
6868

69+
# Open NIfTI and extract numpy array
6970
segmentation = nb.load(segmentation) if isinstance(segmentation, str) else segmentation
71+
segmentation = np.asanyarray(segmentation.dataobj, dtype=int).reshape(-1)
72+
7073
# Map segmentation
7174
if remap_rois or lut is not None:
7275
if lut is None:
73-
lut = np.zeros((256,), dtype="int")
76+
lut = np.zeros((256,), dtype="uint8")
7477
lut[100:201] = 1 # Ctx GM
7578
lut[30:99] = 2 # dGM
7679
lut[1:11] = 3 # WM+CSF
7780
lut[255] = 4 # Cerebellum
7881
# Apply lookup table
79-
segmentation = lut[np.asanyarray(segmentation.dataobj, dtype=int)].reshape(-1)
82+
segmentation = lut[segmentation]
8083

8184
fgmask = segmentation > 0
8285
segmentation = segmentation[fgmask]

0 commit comments

Comments
 (0)