pydicom.pixels.get_packed_frame#
- pydicom.pixels.get_packed_frame(src: bytes, index: int, frame_length: int, start_offset: int = 0, pad: bool = True) bytes [source]#
Retrieve a single bit-packed frame from a bit-packed buffer.
Added in version 3.1.
This should only be used for natively-encoded single bit data (Bits Allocated = 1) in a “bit-packed” representation (one byte containing 8 pixels). The pixel data of such images may have pixel data from multiple frames within a single byte.
See Chapter 5, 8.1.1, particularly the note about multi-frame images with Bits Allocated = 1.
- Parameters:
src (bytes) – The natively encoded bit-packed representation of a full Pixel Data element value, potentially including multiple frames.
index (int) – Non-negative, zero-based index of the frame to extract.
frame_length (int) – Number of pixels in each frame.
start_offset (int, optional) – Position of the first byte of
src
relative to the start of the pixel data. This allows for extraction of a frame from a truncated input buffer containing the desired frame (default0
).pad (bool, optional) – Whether to zero-pad the resulting bytes to a multiple of 2 bytes (default
True
).
- Returns:
Bit-packed representation of the single frame requested.
- Return type:
Note
In certain situations, this function will run faster and use less memory if NumPy is installed. Otherwise, it will fall back to a slower method using native Python functions.