pydicom.encaps.encapsulate_extended_buffer

pydicom.encaps.encapsulate_extended_buffer(buffers: list[BufferedIOBase]) tuple[EncapsulatedBuffer, bytes, bytes][source]

Return EncapsulatedBuffer as well as encoded offsets and lengths for the Extended Offset Table elements.

Added in version 3.0.

Examples

from pydicom import Dataset, FileMetaDataset
from pydicom.encaps import encapsulate_extended_buffer
from pydicom.uid import JPEG2000Lossless

# Open the compressed image frames as io.BufferedReader instances
frame1 = open("frame1.j2k", "rb")
frame2 = open("frame2.j2k", "rb")
frame3 = open("frame3.j2k", "rb")

out: tuple[EncapsulatedBuffer, bytes, bytes] = (
    encapsulate_extended_buffer([frame1, frame2, frame3])
)

ds = Dataset()
ds.file_meta = FileMetaDataset()
ds.file_meta.TransferSyntaxUID = JPEG2000Lossless

ds.PixelData = out[0]
ds.ExtendedOffsetTable = out[1]
ds.ExtendedOffsetTableLengths = out[2]

# Write the encapsulated buffer data to file
ds.save_as("buffered_dataset.dcm")

# Close the buffers
frame1.close()
frame2.close()
frame3.close()
Parameters:

buffers (list[io.BufferedIOBase]) – A list of objects inheriting io.BufferedIOBase containing the compressed Pixel Data frames to be encapsulated.

Returns:

The (EncapsulatedBuffer, extended offset table, extended offset table lengths).

Return type:

tuple[EncapsulatedBuffer, bytes, bytes]