nifti

io

auxiliary.nifti.io.read_nifti(input_nifti_path: str, maintain_dtype: bool = True) ndarray[tuple[int, ...], dtype[_ScalarType_co]]

Read a NIfTI file and return its data as a NumPy array.

Parameters:
  • input_nifti_path (str) – Path to the input NIfTI file.

  • maintain_dtype (bool, optional) – If True, maintain the data type of the NIfTI data. If False, allow data type conversion to float. Default is True.

Returns:

NIfTI data as a NumPy array.

Return type:

numpy.ndarray

auxiliary.nifti.io.write_nifti(input_array: ndarray[tuple[int, ...], dtype[_ScalarType_co]], output_nifti_path: str, reference_nifti_path: str | None = None, create_parent_directory: bool = False) None

Write a NIfTI file from a NumPy array using SimpleITK.

Parameters:
  • input_array (np.ndarray) – The NumPy array containing the data to be written.

  • output_nifti_path (str) – The path where the output NIfTI file will be saved.

  • reference_nifti_path (str, optional) – Path to a reference NIfTI file for spatial metadata.

  • create_parent_directory (bool) – If True, create parent directories if they don’t exist.

Returns:

None