Reputation: 10983
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 (i.e. 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.
Upvotes: 1
Views: 6531
Reputation: 12490
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.
Upvotes: 3