简体   繁体   English

使用gdcm(草根DICOM)解压缩DICOM图像数据

[英]Using gdcm (Grassroots DICOM) to Decompress DICOM Image Data

Is it possible to use the Python wrappers for GDCM to decode the image data in a DICOM file? 是否可以将Python包装器用于GDCM来解码DICOM文件中的图像数据?

I have a byte array / string with the bytes of the image data in a DICOM file (ie the contents of tag 7fe0,0010 ("Pixel Data")) and I want to decode the image to something raw RGB or greyscale. 我有一个byte array / string ,其中包含DICOM文件中图像数据的bytes (即标记7fe0,0010 (“像素数据”)的内容),并且我想将图像解码为原始RGB或灰度。

I am thinking of something along the lines of this but working with just the image data and not a path to the actual DICOM file itself. 我正在考虑一些类似的方法,但是仅使用图像数据,而不是实际DICOM文件本身的路径。

You can read the examples, there is one that shows how one can take an input compressed DICOM and convert it to an uncompressed one. 您可以阅读示例,其中有一个示例说明了如何将输入的压缩DICOM转换为未压缩的DICOM。 See the code online here: 在此处在线查看代码:

If you are a big fan of NumPy, checkout: 如果您是NumPy的忠实粉丝,请查看:

This is sort of a low level example, which shows how to retrieve that actual raw buffer of the image. 这是一个较低级别的示例,它显示了如何检索图像的实际原始缓冲区。

A much nicer class for handling Transfer Syntax conversion would be to use gdcm.ImageChangeTransferSyntax class (allow decompression of icon) 处理Transfer Syntax转换的更好的类是使用gdcm.ImageChangeTransferSyntax类(允许对图标进行解压缩)

If you do not mind reading a little C++, you can trivially convert the following code from C++ to Python: 如果您不介意阅读一点C ++,则可以将以下代码从C ++轻松转换为Python:

Pay attention that this example is actually compressing the image rather than decompressing it. 请注意,此示例实际上是在压缩图像而不是对其进行解压缩

Finally if you really only have access to the data values contains in the Pixel Data attribute, then you should really have a look at (C# syntax should be close to Python syntax): 最后,如果您真的只能访问Pixel Data属性中包含的数据值,那么您应该真正看看(C#语法应与Python语法接近):

This example shows how one can decompress a JPEG Lossless, Nonhierarchical, First- Order Prediction file. 此示例说明了如何解压缩JPEG无损,非分层,一阶预测文件。 The JPEG data is read from file but it should work if the data is already in memory for your case. JPEG数据是从文件中读取的,但如果您的情况下该数据已在内存中,则它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM