nema_quant.io
Input/output utilities for loading images and saving analysis results.
- nema_quant.io.load_nii_image(filepath: Path, return_affine: bool = False, inverse_axes: bool = False) Tuple[numpy.typing.NDArray.typing.Any, numpy.typing.NDArray.typing.Any | None][source]
Load a NIfTI image into a NumPy array.
Reads a .nii or .nii.gz file using SimpleITK and returns the image data as a 3D NumPy array. Optionally returns a 4x4 affine matrix derived from spacing, origin, and direction.
- Parameters:
filepath (pathlib.Path) – Path to the NIfTI image file.
return_affine (bool, optional) – If True, also return the 4x4 affine matrix. Default is False.
- Returns:
numpy.ndarray – 3D image array (z, y, x) in float32.
numpy.ndarray or None – 4x4 affine matrix if return_affine is True, otherwise None.
- Raises:
FileNotFoundError – If filepath does not exist.
ValueError – If the file cannot be loaded as a NIfTI image.