dosma.DicomReader¶
- class dosma.DicomReader(num_workers: int = 0, verbose: bool = False, group_by: Union[str, int, Sequence[Union[str, int]]] = 'EchoNumbers', sort_by: Optional[Union[str, int, Sequence[Union[str, int]]]] = None, ignore_ext: bool = False, default_ornt: Optional[Tuple[str, str]] = None)[source]¶
A class for reading DICOM files.
- Variables
num_workers (int, optional) – Number of workers to use for loading.
verbose (bool, optional) – If
True, show loading progress bar.group_by (str(s) or int(s), optional) – DICOM attribute(s) used to group dicoms. This can be the attribute tag name (str) or tag number (int).
sort_by (str(s) or int(s), optional) – DICOM attribute(s) used to sort dicoms. This sorting is done after sorting files in alphabetical order.
ignore_ext (bool, optional) – If
True, ignore extension (".dcm") when loading dicoms from directory.default_ornt (Tuple[str, str], optional) – Default in-plane orientation to use if orientation cannot be determined from DICOM header. If not specified and orientation cannot be determined, error will be raised.
data_format_code (ImageDataFormat) – The supported image data format.
Examples
>>> # Load single dicom >>> dr = DicomReader() >>> mv = dr.load("/path/to/dicom/file", group_by=None)[0]
>>> # Load multi-echo MRI data >>> dr = DicomReader(num_workers=0, verbose=True) >>> mvs = dr.load("/dicoms/directory", group_by="EchoTime", sort_by="InstanceNumber")
>>> # Use the same loader for multiple multi-echo time-series MRI scans >>> dr = DicomReader(group_by=["EchoTime", "TriggerTime", sort_by="InstanceNumber") >>> scans = [dr.load(dcm_dir) for dcm_dir in ["/dicom/dir1", "/dicom/dir2", "/dicom/dir3"]]
- __init__(num_workers: int = 0, verbose: bool = False, group_by: Union[str, int, Sequence[Union[str, int]]] = 'EchoNumbers', sort_by: Optional[Union[str, int, Sequence[Union[str, int]]]] = None, ignore_ext: bool = False, default_ornt: Optional[Tuple[str, str]] = None)[source]¶
- Parameters
num_workers (int, optional) – Number of workers to use for loading.
verbose (bool, optional) – If
True, show loading progress bar.group_by (
str(s)orint(s), optional) – DICOM attribute(s) used to group dicoms. This can be the attribute tag name (str) or tag number (int).sort_by (
str(s)orint(s), optional) – DICOM attribute(s) used to sort dicoms. This sorting is done after sorting files in alphabetical order.ignore_ext (bool, optional) – If
True, ignore extension (".dcm") when loading dicoms from directory.default_ornt (Tuple[str, str], optional) – Default in-plane orientation to use if orientation cannot be determined from DICOM header. If not specified and orientation cannot be determined, error will be raised.
Methods
__init__([num_workers, verbose, group_by, …])- param num_workers
Number of workers to use for loading.
get_files(path[, include, exclude, …])Get dicom files from directory.
load(path[, group_by, sort_by, ignore_ext, …])Load dicoms into
MedicalVolume``s grouped by ``group_bytag(s).load_state_dict(state_dict)Loads the state dictionary into the object.
state_dict()Returns the state dictionary for an object.
Attributes
data_format_code