load_dicom#

deepinv.utils.load_dicom(fname, as_tensor=True, apply_rescale=False, dtype=np.float32, **kwargs)[source]#

Load image from DICOM file.

Requires pydicom to be installed. Install it with pip install pydicom.

Parameters:
  • fname (str, pathlib.Path) – path to DICOM file or buffer.

  • as_tensor (bool) – if True, return as torch tensor (default), otherwise return as numpy array.

  • apply_rescale (bool) – if True, map the stored values (SV) to output values according to the pydicom apply_rescale, default False. See pydicom docs and apply_rescale for details. Note this is only useful when the appropriate dicom tags are present, for example in CT for deepinv.datasets.LidcIdriSliceDataset for converting to Hounsfield Units. For other applications such as SUV/PET, we recommend applying the rescaling yourself.

  • dtype (numpy.dtype, str) – data type to use when loading the nifti file.

Returns:

either numpy array of shape of raw data (...), or torch float tensor of shape (1, ...) where ... are the DICOM image dimensions.

Return type:

Tensor | ndarray

Examples using load_dicom:#

Loading scientific images

Loading scientific images