Newer
Older
"""
Utility methods for dealing with different file types.
"""

Tamino Huxohl
committed
from pydicom.misc import is_dicom

Tamino Huxohl
committed
from mu_map.file.dicom import load_dcm, load_dcm_img
from mu_map.file.interfile import load_interfile, load_interfile_img, Interfile
def load_as_interfile(filename: str, **kwargs) -> Interfile:
"""
Load a file as an Interfile image even if it is
in DICOM format.
Parameters
----------
filename: str
the file to be loaded in Interfile format
kwargs
parameters passed to load_dcm if the file is a DICOM file
"""
if is_dicom(filename):
return dicom_to_interfile(*load_dcm(filename, **kwargs))
else:
return load_interfile(filename)
def load_img(filename: str, **kwargs) -> np.ndarray:
"""
Load a file as a numpy array.
Parameters
----------
filename: str
filename: the file to be loaded
kwargs
parameters passed to load_dcm_img if the file is a DICOM file
Return
------
np.ndarray
"""
if is_dicom(filename):
return load_dcm_img(filename, **kwargs)
else:
return load_interfile_img(filename)