pydicom.encaps.generate_pixel_data

pydicom.encaps.generate_pixel_data(bytestream: bytes, nr_frames: Optional[int] = None) Generator[Tuple[bytes, ...], None, None][source]

Yield an encapsulated pixel data frame.

For the following transfer syntaxes, a fragment may not contain encoded data from more than one frame. However data from one frame may span multiple fragments.

  • 1.2.840.10008.1.2.4.50 - JPEG Baseline (Process 1)

  • 1.2.840.10008.1.2.4.51 - JPEG Baseline (Process 2 and 4)

  • 1.2.840.10008.1.2.4.57 - JPEG Lossless, Non-Hierarchical (Process 14)

  • 1.2.840.10008.1.2.4.70 - JPEG Lossless, Non-Hierarchical, First-Order Prediction (Process 14 [Selection Value 1])

  • 1.2.840.10008.1.2.4.80 - JPEG-LS Lossless Image Compression

  • 1.2.840.10008.1.2.4.81 - JPEG-LS Lossy (Near-Lossless) Image Compression

  • 1.2.840.10008.1.2.4.90 - JPEG 2000 Image Compression (Lossless Only)

  • 1.2.840.10008.1.2.4.91 - JPEG 2000 Image Compression

  • 1.2.840.10008.1.2.4.92 - JPEG 2000 Part 2 Multi-component Image Compression (Lossless Only)

  • 1.2.840.10008.1.2.4.93 - JPEG 2000 Part 2 Multi-component Image Compression

For the following transfer syntaxes, each frame shall be encoded in one and only one fragment.

  • 1.2.840.10008.1.2.5 - RLE Lossless

Parameters
  • bytestream (bytes) – The value of the (7FE0,0010) Pixel Data element from an encapsulated dataset. The Basic Offset Table item should be present and the Sequence Delimiter item may or may not be present.

  • nr_frames (int, optional) – Required for multi-frame data when the Basic Offset Table is empty and there are multiple frames. This should be the value of (0028,0008) Number of Frames.

Yields

tuple of bytes – An encapsulated pixel data frame, with the contents of the tuple the frame’s fragmented data.

Notes

If the Basic Offset Table is empty and there are multiple fragments per frame then an attempt will be made to locate the frame boundaries by searching for the JPEG/JPEG-LS/JPEG2000 EOI/EOC marker (0xFFD9). If the marker is not present or the pixel data hasn’t been compressed using one of the JPEG standards then the generated pixel data may be incorrect.

References

DICOM Standard Part 5, Annex A