Module preprocessor.dicom
Preprocessing for DICOM (Digital Images and Communications in Medicine) images.
DICOM is a standardized format commonly used for medical imaging such as
ultrasound, x-ray, and CT scan images.
The DicomPreprocessor
allows import
and manipulation of data in this format.
Typical usage:
# Read a DICOM image file, interpreting pixels as int16 values in a NumPy ndarray
pre = DicomPreprocessor.builder().dtype("int16").output_numpy()
pre.read_file(get_testdata_file("CT_small.dcm"))
Classes
class DicomNumpyPreprocessor (dtype: str)
-
DICOM Preprocessor to generate numpy.ndarray representations of image data
Ancestors
- DicomPreprocessor
- NumpyPreprocessor
- abc.ABC
Methods
def read_asset(self, asset: Union[str, pathlib.Path, Package]) -> numpy.ndarray
-
Not implemented for DICOM, the files are their own package format.
def read_asset_chunked(self, asset: Union[str, pathlib.Path, Package], chunksize: int) -> Iterator[numpy.ndarray]
-
Not implemented for DICOM, the files are their own package format.
def read_bytes(self, data: _io.BytesIO) -> numpy.ndarray
-
Read a BytesIO source as a DICOM file as as an ndarray.
Args
data
:BytesIO
- BytesIO source containing the DICOM data.
Returns
np.ndarray
- Image data represented as an ndarray.
def read_file(self, asset: Union[str, pathlib.Path, Package]) -> numpy.ndarray
-
Read the DICOM file from disk as a numpy.ndarray.
Args
path
:Union[str, Path, Package]
- Path to the DICOM file.
Returns
np.ndarray
- Image data represented as an ndarray.
def read_folder(self, pattern: str) -> Iterator[numpy.ndarray]
-
Read a folder of DICOM files from disk as as a group of ndarrays.
Args
pattern
:str
- A glob pattern used to select files to read. Ex. "data/sample*.dcm"
Yields
Iterator[np.ndarray]
- Image data represented as an ndarray.
Inherited members
class DicomPreprocessor
-
DICOM image preprocessor
Subclasses
Static methods
def builder() -> DicomPreprocessorBuilder
class DicomPreprocessorBuilder
-
Utility for defining a DICOM preprocessing pipeline.
Ancestors
- OutputNumpy
- RequirePropertyDtype
- IsDict
- abc.ABC
Class variables
var SCHEMA
Methods
def dtype(self, dtype: Optional[str]) -> DicomPreprocessorBuilder
-
Cast the output numpy array to the given dtype.
Args
dtype
- The dtype that a numpy output will be cast into. If not set, the operation will choose. Ignored for non-numpy outputs. See NumPy docs for more detail on possible types.
Returns
DicomPreprocessorBuilder
- This class instance, useful for chaining.
def output_numpy(self) -> NumpyPreprocessor
-
Complete the builder and return a DicomNumpyPreprocessor
Returns
NumpyPreprocessor
- A NumpyPreprocessor
Inherited members