Skip to content
Snippets Groups Projects
util.py 1.22 KiB
Newer Older
"""
Utility methods for dealing with different file types.
"""
import numpy as np
Tamino Huxohl's avatar
Tamino Huxohl committed
from mu_map.file.convert import dicom_to_interfile
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.

Tamino Huxohl's avatar
Tamino Huxohl committed
    Parameters
    ----------
    filename: str
        the file to be loaded in Interfile format
    kwargs
        parameters passed to load_dcm if the file is a DICOM file
Tamino Huxohl's avatar
Tamino Huxohl committed

    Returns
    -------
    Interfile
    """
    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.

Tamino Huxohl's avatar
Tamino Huxohl committed
    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)