Handling of compressed image data¶

How to get image data from compressed DICOM images

Preconditions¶

To be able to decompress compressed DICOM image data, you need to have one or more packages installed that are able to handle this kind of data. pydicom detects the installed packages and provides image data handlers that use the available packages.

The following packages can be used with pydicom:

• GDCM - this is the package that supports most compressed formats
• Pillow, ideally with jpeg and jpeg2000 plugins
• jpeg_ls

Note that you always need the NumPy package to be able to handle image data.

Caution

We rely on the image handling capacity of the mentioned packages and cannot guarantee the correctness of the generated uncompressed images. Be sure to verify the correctness of generated images using other means before you use them for medical purposes.

Supported Transfer Syntaxes¶

As far as we have been able to verify, the following transfer syntaxes are handled by the given packages:

Transfer Syntax NumPy NumPy + JPEG-LS NumPy + GDCM NumPy + Pillow
Name UID
Explicit VR Little Endian 1.2.840.10008.1.2.1
Implicit VR Little Endian 1.2.840.10008.1.2
Explicit VR Big Endian 1.2.840.10008.1.2.2
Deflated Explicit VR Little Endian 1.2.840.10008.1.2.1.99
RLE Lossless 1.2.840.10008.1.2.5
JPEG Baseline (Process 1) 1.2.840.10008.1.2.4.50     1
JPEG Extended (Process 2 and 4) 1.2.840.10008.1.2.4.51     1
JPEG Lossless (Process 14) 1.2.840.10008.1.2.4.57
JPEG Lossless (Process 14, SV1) 1.2.840.10008.1.2.4.70
JPEG LS Lossless 1.2.840.10008.1.2.4.80
JPEG LS Lossy 3 1.2.840.10008.1.2.4.81
JPEG2000 Lossless 1.2.840.10008.1.2.4.90     2
JPEG2000 4 1.2.840.10008.1.2.4.91       5
JPEG2000 Multi-component Lossless 1.2.840.10008.1.2.4.92
JPEG2000 Multi-component 1.2.840.10008.1.2.4.93
1 only with JpegImagePlugin
2 only with Jpeg2KImagePlugin
3 handled differently by Pillow and GDCM
4 no support for 8 bit Grayscale
5 not supported for > 8 bit

Usage¶

To use decompressed image data from compressed DICOM images, you have two options:

• use decompress() on the dataset to convert it in-place and work with the pixel data as described before
• get an uncompressed copy of the pixel data as a NumPy array using Dataset.pixel_array without touching the original dataset

Note

Using decompress() adapts the transfer syntax of the data set, but not the Photometric Interpretation. The Photometric Interpretation may not match the pixel data, depending on the used decompression handler.