pydicom.pixels.concatenate_packed_frames#

pydicom.pixels.concatenate_packed_frames(frames: Sequence[bytes | bytearray], frame_length: int, pad: bool = True) bytes[source]#

Concatenate individual bit-packed frames.

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). Concatenating such frames may require combining pixels 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:
  • frames (Sequence[bytes | bytearray]) – List of individual frames in native bit-packed representation.

  • frame_length (int) – Number of pixels in each frame.

  • pad (bool, optional) – Whether to zero-pad the resulting bytes to a multiple of 2 bytes (default True).

Returns:

Bit-packed representation of all frames combined.

Return type:

bytes

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.