[英]How do I read and then write a multi-frame DICOM file in pydicom without an image offset?
I read a multi-frame DICOM file with pydicom, after that I write it into a new file.我用 pydicom 读取了一个多帧 DICOM 文件,然后将其写入一个新文件。 However when I open the DICOM file, the image has an offset/shift.
但是,当我打开 DICOM 文件时,图像有偏移/偏移。
ds = pydicom.dcmread('./Multiframe/0020.dcm')
arr = ds.pixel_array
ds.PixelData = encapsulate([arr[0].tobytes(),
arr[1].tobytes(),
arr[2].tobytes(),
arr[3].tobytes(),
arr[4].tobytes(),
arr[5].tobytes(),
arr[6].tobytes(),
arr[7].tobytes(),
arr[8].tobytes(),
arr[9].tobytes(),
arr[10].tobytes()])
ds.save_as('new.dcm', write_like_original=False)
What is wrong with the code?代码有什么问题? It works if I write a simple image (not multi-frame), the problem is with the encapsulation.
如果我写一个简单的图像(不是多帧),它就可以工作,问题出在封装上。
Encapsulation of Pixel Data (both single and multi-framed) is only required for compressed transfer syntaxes, such as JPEG or RLE Lossless.仅压缩传输语法(例如 JPEG 或 RLE Lossless)需要封装像素数据(单帧和多帧)。 If you have an uncompressed syntax such as Explicit VR Little Endian then no encapsulation is necessary:
如果您有未压缩的语法,例如 Explicit VR Little Endian,则无需封装:
ds = pydicom.dcmread('./Multiframe/0020.dcm')
arr = ds.pixel_array
if ds.file_meta.TransferSyntaxUID.is_compressed:
raise AttributeError("Encapsulation required for compressed transfer syntaxes")
ds.PixelData = arr.tobytes()
ds.save_as('new.dcm', write_like_original=False)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.