pydicom.encaps.encapsulate_buffer¶
- pydicom.encaps.encapsulate_buffer(buffers: list[BufferedIOBase], has_bot: bool = True) EncapsulatedBuffer [source]¶
Return an
EncapsulatedBuffer
instance from buffers.Added in version 3.0.
Examples
from pydicom import Dataset, FileMetaDataset from pydicom.encaps import encapsulate_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") ds = Dataset() ds.file_meta = FileMetaDataset() ds.file_meta.TransferSyntaxUID = JPEG2000Lossless ds.PixelData = encapsulate_buffer([frame1, frame2, frame3]) # 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:
A
EncapsulatedBuffer
instance that can be used as the value for a Pixel Data element.- Return type: