pydicom.encaps.generate_pixel_data_fragment(fp: DicomFileLike) Generator[bytes, None, None][source]

Yield the encapsulated pixel data fragments.

For compressed (encapsulated) Transfer Syntaxes, the (7FE0,0010) Pixel Data element is encoded in an encapsulated format.


The encoded pixel data stream is fragmented into one or more Items. The stream may represent a single or multi-frame image.

Each Data Stream Fragment shall have tag of (FFFE,E000), followed by a 4 byte Item Length field encoding the explicit number of bytes in the Item. All Items containing an encoded fragment shall have an even number of bytes greater than or equal to 2, with the last fragment being padded if necessary.

The first Item in the Sequence of Items shall be a ‘Basic Offset Table’, however the Basic Offset Table item value is not required to be present. It is assumed that the Basic Offset Table item has already been read prior to calling this function (and that fp is positioned past this item).

The remaining items in the Sequence of Items are the pixel data fragments and it is these items that will be read and returned by this function.

The Sequence of Items is terminated by a (FFFE,E0DD) Sequence Delimiter Item with an Item Length field of value 0x00000000. The presence or absence of the Sequence Delimiter Item in fp has no effect on the returned fragments.


The encoding of the data shall be little endian.


fp (filebase.DicomFileLike) – The encoded (7FE0,0010) Pixel Data element value, positioned at the start of the item tag for the first item after the Basic Offset Table item. fp.is_little_endian should be set to True.


bytes – A pixel data fragment.


ValueError – If the data contains an item with an undefined length or an unknown tag.


DICOM Standard Part 5, Annex A.4