pydicom.pixels.decoders.base.DecodeRunner¶
- class pydicom.pixels.decoders.base.DecodeRunner(tsyntax: UID)[source]¶
Class for managing the pixel data decoding process.
Added in version 3.0.
This class is not intended to be used directly. For decoding pixel data use the
Decoder
instance corresponding to the transfer syntax of the pixel data.- __init__(tsyntax: UID) None [source]¶
Create a new runner for decoding data encoded as tsyntax.
- Parameters:
tsyntax (pydicom.uid.UID) – The transfer syntax UID corresponding to the pixel data to be decoded.
Methods
__init__
(tsyntax)Create a new runner for decoding data encoded as tsyntax.
decode
(index)Decode the frame of pixel data at index.
del_option
(name)Delete option name from the runner.
frame_length
([unit])Return the expected length (in number of bytes or pixels) of each frame of pixel data.
get_data
(src, offset, length)Return length bytes from src, starting at offset.
get_option
(name[, default])Return the value of the option name.
Yield decoded frames from the encoded pixel data.
pixel_properties
([as_frame])Return a dict containing the Image Pixel module related properties.
process
(arr)Return arr after applying zero or more processing operations.
reshape
(arr[, as_frame])Return a reshaped
ndarray
arr.set_decoders
(decoders)Set the decoders use for decoding compressed pixel data.
set_option
(name, value)Set a runner option.
set_options
(**kwargs)Set multiple runner options.
set_source
(src)Set the pixel data to be decoded.
validate
()Validate the decoding options and source buffer (if any).
Attributes
Return the expected number of bits allocated used by the data.
Return the expected number of bits stored used by the data.
Return the expected number of columns in the data.
Return the extended offsets table and lengths
Return
True
if the pixel data source is anndarray
Return
True
if the pixel data source is BinaryIOReturn
True
if the pixel data source is a buffer-likeReturn
True
if the pixel data source is aDataset
Return the expected number of frames in the data.
Return a reference to the runner's options dict.
Return the expected photometric interpretation of the data.
Return a
numpy.dtype
suitable for containing the decoded pixel data.Return the expected pixel keyword of the data.
Return the expected pixel representation of the data.
Return the expected planar configuration of the data.
Return the expected number of rows in the data.
Return the expected number of samples per pixel in the data.
Return the buffer-like or file-like containing the encoded pixel data.
Return the expected transfer syntax corresponding to the data.
- property extended_offsets: tuple[list[int], list[int]] | tuple[bytes, bytes] | None¶
Return the extended offsets table and lengths
- frame_length(unit: str = 'bytes') int | float [source]¶
Return the expected length (in number of bytes or pixels) of each frame of pixel data.
- Parameters:
unit (str, optional) – If
"bytes"
then returns the expected length of the pixel data in whole bytes and NOT including an odd length trailing NULL padding byte. If"pixels"
then returns the expected length of the pixel data in terms of the total number of pixels (default"bytes"
).- Returns:
The expected length of a single frame of pixel data in either whole bytes or pixels, excluding the NULL trailing padding byte for odd length data. For “pixels”, an integer will always be returned. For “bytes”, a float will be returned for images with BitsAllocated of 1 whose frames do not consist of a whole number of bytes.
- Return type:
- get_data(src: bytes | bytearray | memoryview | BinaryIO, offset: int, length: int) bytes [source]¶
Return length bytes from src, starting at offset.
- Parameters:
- Returns:
The data from src, may return fewer bytes if the end of src is reached before
offset + length
.- Return type:
- get_option(name: str, default: Any | None = None) Any [source]¶
Return the value of the option name.
- iter_decode() Iterator[bytes | bytearray] [source]¶
Yield decoded frames from the encoded pixel data.
- property options: DecodeOptions | EncodeOptions¶
Return a reference to the runner’s options dict.
- property photometric_interpretation: str¶
Return the expected photometric interpretation of the data.
- property pixel_dtype: dtype¶
Return a
numpy.dtype
suitable for containing the decoded pixel data.
- property pixel_keyword: str¶
Return the expected pixel keyword of the data.
- Returns:
One of
"PixelData"
,"FloatPixelData"
,"DoubleFloatPixelData"
- Return type:
- pixel_properties(as_frame: bool = False) dict[str, str | int] [source]¶
Return a dict containing the Image Pixel module related properties.
- Parameters:
as_frame (bool, optional) – If
True
then don’t include properties that aren’t appropriate for a single frame. DefaultFalse
.- Returns:
A dict containing the values for:
bits_allocated
bits_stored
columns
photometric_interpretation
samples_per_pixel
rows
number_of_frames
planar_configuration (if samples_per_pixel > 1)
pixel_representation (if the pixel keyword is
"PixelData"
)
The returned values depend on whether or not this method is called before or after decoding the pixel data, as the decoding plugins and image processing functions may update the values as needed to reflect the corresponding decoded data. For example, if the pixel data is converted from the YCbCr to RGB color space then the photometric_interpretation value will be changed to match after the data has been decoded.
- Return type:
- process(arr: ndarray) tuple[np.ndarray, dict[str, str | int]] [source]¶
Return arr after applying zero or more processing operations.
- Returns:
numpy.ndarray – The array with the applied processing.
dict[str, int | str] – A
dict
containing any required changes to the image pixel properties due to the processing.
- reshape(arr: ndarray, as_frame: bool = False) ndarray [source]¶
Return a reshaped
ndarray
arr.- Parameters:
arr (np.ndarray) – The 1D array to be reshaped.
as_frame (bool, optional) – If
True
then treat arr as only containing a single frame’s worth of pixel data, otherwise treat arr as containing the full amount of pixel data (default).
- Returns:
A view of the input arr reshaped to:
(rows, columns) for single frame, single sample data
(rows, columns, samples) for single frame, multi-sample data
(frames, rows, columns) for multi-frame, single sample data
(frames, rows, columns, samples) for multi-frame, multi-sample data
- Return type:
np.ndarray
- set_decoders(decoders: dict[str, Callable[[bytes, DecodeRunner], bytes | bytearray]]) None [source]¶
Set the decoders use for decoding compressed pixel data.
- set_option(name: str, value: Any) None [source]¶
Set a runner option.
- Parameters:
name (str) – The name of the option to be set.
value (Any) – The value of the option.
- set_source(src: Buffer | Dataset | BinaryIO) None [source]¶
Set the pixel data to be decoded.
- Parameters:
src (bytes | bytearray | memoryview | pydicom.dataset.Dataset) – If a buffer-like then the encoded pixel data, otherwise the
Dataset
containing the pixel data and associated group0x0028
elements.
- property src: bytes | bytearray | memoryview | BinaryIO¶
Return the buffer-like or file-like containing the encoded pixel data.