Load DICOM
imgtools.dicom.load_dicom
load_dicom(
dicom_input: imgtools.dicom.input.dicom_reader.DicomInput,
force: bool = True,
stop_before_pixels: bool = True,
) -> pydicom.dataset.FileDataset
Load a DICOM file and return the parsed FileDataset object.
This function supports various input types including file paths, byte streams,
and file-like objects. It uses the pydicom.dcmread
function to read the DICOM file.
Notes
- If
dicom_input
is already aFileDataset
, it is returned as is. - If
dicom_input
is a file path or file-like object, it is read usingpydicom.dcmread
. - If
dicom_input
is a byte stream, it is wrapped in aBytesIO
object and then read. - An
InvalidDicomError
is raised if the input type is unsupported.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
pydicom.dataset.FileDataset | str | pathlib.Path | bytes | typing.BinaryIO
|
Input DICOM file as a |
required |
|
bool
|
Whether to allow reading DICOM files missing the File Meta Information header, by default True. |
True
|
|
bool
|
Whether to stop reading the DICOM file before loading pixel data, by default True. |
True
|
Returns:
Type | Description |
---|---|
pydicom.dataset.FileDataset
|
Parsed DICOM dataset. |
Raises:
Type | Description |
---|---|
imgtools.exceptions.InvalidDicomError
|
If the input is of an unsupported type or cannot be read as a DICOM file. |
Source code in src/imgtools/dicom/input/dicom_reader.py
imgtools.dicom.load_rtstruct_dcm
load_rtstruct_dcm(
rtstruct_input: imgtools.dicom.input.dicom_reader.DicomInput,
force: bool = True,
stop_before_pixels: bool = True,
) -> pydicom.dataset.FileDataset
Load an RTSTRUCT DICOM file and return the parsed FileDataset object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
pydicom.dataset.FileDataset | str | pathlib.Path | bytes
|
Input DICOM file as a |
required |
|
bool
|
Whether to allow reading DICOM files missing the File Meta Information header, by default True. |
True
|
|
bool
|
Whether to stop reading the DICOM file before loading pixel data, by default True. |
True
|
Returns:
Type | Description |
---|---|
pydicom.dataset.FileDataset
|
Parsed RTSTRUCT DICOM dataset. |
Raises:
Type | Description |
---|---|
imgtools.exceptions.InvalidDicomError
|
If the input is of an unsupported type or cannot be read as a DICOM file. |
imgtools.exceptions.NotRTSTRUCTError
|
If the input file is not an RTSTRUCT (i.e., |
Source code in src/imgtools/dicom/input/dicom_reader.py
imgtools.dicom.load_seg_dcm
load_seg_dcm(
seg_input: imgtools.dicom.input.dicom_reader.DicomInput,
force: bool = True,
stop_before_pixels: bool = True,
) -> pydicom.dataset.FileDataset
Load a SEG DICOM file and return the parsed FileDataset object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
pydicom.dataset.FileDataset | str | pathlib.Path | bytes
|
Input DICOM file as a |
required |
|
bool
|
Whether to allow reading DICOM files missing the File Meta Information header, by default True. |
True
|
|
bool
|
Whether to stop reading the DICOM file before loading pixel data, by default True. |
True
|
Returns:
Type | Description |
---|---|
pydicom.dataset.FileDataset
|
Parsed SEG DICOM dataset. |
Raises:
Type | Description |
---|---|
imgtools.exceptions.InvalidDicomError
|
If the input is of an unsupported type or cannot be read as a DICOM file. |
imgtools.exceptions.NotSEGError
|
If the input file is not a SEG (i.e., |