Skip to content

Commit ac54f47

Browse files
committed
fix: error handling the segmentation in NIfTI extraction
1 parent 8c0b6a6 commit ac54f47

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

niworkflows/utils/timeseries.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ 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:
@@ -76,7 +79,7 @@ def _nifti_timeseries(
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)