Fix NIfTI viewer read-only array handling
This commit is contained in:
4
app.py
4
app.py
@@ -134,9 +134,9 @@ def load_nifti_cached(path: str, max_voxels: int = 14_000_000) -> Tuple[np.ndarr
|
|||||||
spatial_slices = (slice(None, None, stride), slice(None, None, stride), slice(None, None, stride))
|
spatial_slices = (slice(None, None, stride), slice(None, None, stride), slice(None, None, stride))
|
||||||
|
|
||||||
if len(img.shape) == 4:
|
if len(img.shape) == 4:
|
||||||
data = np.asarray(img.dataobj[spatial_slices + (slice(None),)], dtype=np.float32)
|
data = np.array(img.dataobj[spatial_slices + (slice(None),)], dtype=np.float32, copy=True)
|
||||||
else:
|
else:
|
||||||
data = np.asarray(img.dataobj[spatial_slices], dtype=np.float32)
|
data = np.array(img.dataobj[spatial_slices], dtype=np.float32, copy=True)
|
||||||
data = np.nan_to_num(data, copy=False)
|
data = np.nan_to_num(data, copy=False)
|
||||||
spacing = tuple(float(v) * stride for v in img.header.get_zooms()[:3])
|
spacing = tuple(float(v) * stride for v in img.header.get_zooms()[:3])
|
||||||
return data, spacing, stride # type: ignore[return-value]
|
return data, spacing, stride # type: ignore[return-value]
|
||||||
|
|||||||
Reference in New Issue
Block a user