load_nifti#
- deepinv.utils.load_nifti(fname, as_memmap=False, dtype=np.float32, **kwargs)[source]#
Load volume from nifti file as torch tensor.
We assume that the data contains a channel dimension. If not, unsqueeze the output to add a channel dimension
x = load_nifti(...).unsqueeze(0).Warning
When loading zipped nifti files (e.g., .nii.gz), it is recommended to install indexed_gzip (
pip install indexed-gzip) to speed up loading times.- Parameters:
fname (str, pathlib.Path) – file to load.
as_memmap (bool,) – open this file as a proxy array, which does not eagerly load the entire array into memory. This is useful when extracting patches from large arrays or to quickly infer dtype and shape.
dtype (numpy.dtype, str) – data type to use when loading the nifti file. This is ignored if
as_memmapisTrue.
- Returns:
torch.Tensorcontaining nifti image. Ifas_memmapisTrue, returns a proxy array instead.- Return type:
torch.Tensor | nib.arrayproxy.ArrayProxy