Spaces:
Running on Zero
Running on Zero
File size: 475 Bytes
ab1db83 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | from __future__ import annotations
from pathlib import Path
import nibabel as nib
import numpy as np
def load_volume(path: str | Path) -> tuple[np.ndarray, np.ndarray]:
img = nib.load(str(path))
return np.asarray(img.dataobj), img.affine
def percentile_window(data: np.ndarray, lo: float = 2.0, hi: float = 98.0) -> tuple[float, float]:
nz = data[data > 0] if (data > 0).any() else data
return float(np.percentile(nz, lo)), float(np.percentile(nz, hi))
|