nifreeze.utils.ndimage module

nifreeze.utils.ndimage.get_data(img: ImgT, dtype: dtype | str | None = None) ndarray[source]

Extracts the data array from a nibabel image, handling data type and scaling.

This function retrieves the data from a nibabel image object, optionally casting it to a specified data type. If the requested dtype is a floating point type, the function ensures that the data is loaded as floats, applying any scaling factors if present. Otherwise, it attempts to return the raw data array, avoiding unnecessary type conversion or scaling when possible.

Parameters:
  • img (SpatialImage) – A nibabel image object from which to extract the data.

  • dtype (dtype or str, optional) – Desired data type for the output array.

Returns:

The image data as a NumPy array, with type and scaling as specified.

Return type:

ndarray

nifreeze.utils.ndimage.load_api(path: str | PathLike[str], api: type[ImgT]) ImgT[source]