Handling of compressed pixel data¶
How to get compressed pixel data
Preconditions¶
To be able to decompress compressed DICOM pixel data, you need to install one or more packages that are able to handle the format the data is encoded in.
The following packages can be used with pydicom:
GDCM - this is the package that supports most compressed formats
Pillow, ideally with
jpeg
andjpeg2000
pluginspylibjpeg, with the
-libjpeg
and-openjpeg
plugins
Note that you always need the NumPy package to be able to handle pixel data.
Caution
We rely on the data handling capacity of the mentioned packages and cannot guarantee the correctness of the generated uncompressed pixel data. Be sure to verify the correctness of the output using other means before you use them for medical purposes.
Supported Transfer Syntaxes¶
To get the transfer syntax of a dataset you can do:
>>> from pydicom import dcmread
>>> ds = dcmread('path/to/dicom/file')
>>> ds.file_meta.TransferSyntaxUID
'1.2.840.10008.1.2.1'
>>> ds.BitsAllocated
16
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
|
NumPy +
pylibjpeg
|
|
---|---|---|---|---|---|---|
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 |
✓4 |
||
JPEG Extended (Process 2 and 4) |
1.2.840.10008.1.2.4.51 |
✓ |
✓1,3 |
✓4 |
||
JPEG Lossless (Process 14) |
1.2.840.10008.1.2.4.57 |
✓ |
✓4 |
|||
JPEG Lossless (Process 14, SV1) |
1.2.840.10008.1.2.4.70 |
✓ |
✓4 |
|||
JPEG LS Lossless |
1.2.840.10008.1.2.4.80 |
✓ |
✓ |
✓4 |
||
JPEG LS Lossy |
1.2.840.10008.1.2.4.81 |
✓ |
✓ |
✓4 |
||
JPEG2000 Lossless |
1.2.840.10008.1.2.4.90 |
✓ |
✓2 |
✓5 |
||
JPEG2000 |
1.2.840.10008.1.2.4.91 |
✓ |
✓2 |
✓5 |
||
JPEG2000 Multi-component Lossless |
1.2.840.10008.1.2.4.92 |
|||||
JPEG2000 Multi-component |
1.2.840.10008.1.2.4.93 |
Usage¶
To get uncompressed pixel data you have two options:
use
decompress()
on the dataset to convert it in-place and work with the pixel data as described beforeget an uncompressed copy of the pixel data as a NumPy
ndarray
usingDataset.pixel_array
without changing 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.