safe_load_4dpet_nifti#

petpal.utils.image_io.safe_load_4dpet_nifti(filename: str) nibabel.nifti1.Nifti1Image#

Safely load a 4D PET NIfTI file.

This function checks if the given file has a ‘.nii’ or ‘.nii.gz’ extension, then tries to load it as a NIfTI file using the nibabel library. If the file cannot be loaded, it raises an exception.

Parameters:

filename (str) – The path of the NIfTI file to be loaded.

Returns:

Nifti1Image – The loaded NIfTI 4D PET image.

Raises:
  • ValueError – If the file does not have a ‘.nii’ or ‘.nii.gz’ extension.

  • Exception – If an error occurred while loading the NIfTI file.