简体   繁体   中英

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?

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.

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.

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. See the code online here:

If you are a big fan of NumPy, checkout:

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)

If you do not mind reading a little C++, you can trivially convert the following code from C++ to 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):

This example shows how one can decompress a JPEG Lossless, Nonhierarchical, First- Order Prediction file. The JPEG data is read from file but it should work if the data is already in memory for your case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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