Plugins for Pixel Data compression and decompression#

The default installation of pydicom doesn’t support decompression or compression of Pixel Data, except for RLE Lossless and Deflated Image Frame Compression. Support for other compressed transfer syntaxes is added through plugins, each of which requires installing NumPy and one or more third-party packages.

To determine the transfer syntax used by a dataset you can use the following snippet:

from pydicom import dcmread

ds = dcmread("path/to/dataset")
print(ds.file_meta.TransferSyntaxUID.name)

Plugins for decompression#

The table below lists the plugins available for decompressing pixel data that’s been compressed using the method corresponding to the Transfer Syntax UID. No plugins are required for uncompressed pixel data, as pydicom can handle these natively as long as NumPy is installed.

If your dataset uses a compressed transfer syntax that isn’t listed below then you’ll have to rely on third-party methods for decoding, as described here.

Supported Transfer Syntaxes#

Transfer Syntax

Plugins

Name

UID

pylibjpeg

gdcm

pillow

pyjpegls

pydicom

JPEG Baseline 8-bit

1.2.840.10008.1.2.4.50

1

JPEG Extended 12-bit

1.2.840.10008.1.2.4.51

1

JPEG Lossless P14

1.2.840.10008.1.2.4.57

1

JPEG Lossless SV1

1.2.840.10008.1.2.4.70

1

JPEG-LS Lossless

1.2.840.10008.1.2.4.80

1

JPEG-LS Near Lossless

1.2.840.10008.1.2.4.81

1

JPEG 2000 Lossless

1.2.840.10008.1.2.4.90

2

4

JPEG 2000

1.2.840.10008.1.2.4.91

2

4

HTJ2K Lossless

1.2.840.10008.1.2.4.201

2

HTJ2K Lossless RPCL

1.2.840.10008.1.2.4.202

2

HTJ2K

1.2.840.10008.1.2.4.203

2

RLE Lossless

1.2.840.10008.1.2.5

3

Deflated Image Frame Compression

1.2.840.10008.1.2.8.1

1 with pylibjpeg-libjpeg
2 with pylibjpeg-openjpeg
3 with pylibjpeg-rle
4 with Pillow’s Jpeg2KImagePlugin

Plugin requirements and limitations#

Plugin

Requires

Known limitations

pylibjpeg

pylibjpeg and at least one of pylibjpeg-libjpeg, pylibjpeg-openjpeg and pylibjpeg-rle

  • Maximum supported Bits Stored for JPEG 2000 and HTJ2K is 24

gdcm

python-gdcm

  • JPEG Extended 12-bit is only available if Bits Allocated is 8

  • JPEG-LS Near Lossless only if Bits Stored is at least 8 for a Pixel Representation of 1

  • JPEG-LS Lossless and JPEG-LS Near Lossless only if Bits Stored is not 6 or 7

  • Maximum supported Bits Stored is 16

pillow

Pillow, with support for JPEG 2000 via Pillow’s Jpeg2KImagePlugin

  • JPEG Extended 12-bit is only available if Bits Allocated is 8

  • JPEG 2000 Lossless and JPEG 2000 are only available for a Samples per Pixel of 3 when Bits Stored is <= 8

  • Maximum supported Bits Stored is 16

pyjpegls

pyjpegls

pydicom

pydicom

  • RLE Lossless: Slower than the other plugins by 3-4x

Plugins for compression#

The table below lists the plugins available for compressing pixel data using the method corresponding to the Transfer Syntax UID. If you wish to use a compression method that isn’t listed below then you’ll have to rely on third-party methods for encoding, as described here.

Supported Transfer Syntaxes#

Transfer Syntax

Plugins

Encoding guide

Name

UID

JPEG-LS Lossless
JPEG-LS Near Lossless
1.2.840.10008.1.2.4.80
1.2.840.10008.1.2.4.81

pyjpegls

JPEG-LS

JPEG 2000 Lossless
JPEG 2000
1.2.840.10008.1.2.4.90
1.2.840.10008.1.2.4.91

pylibjpeg

JPEG 2000

RLE Lossless

1.2.840.10008.1.2.5

pylibjpeg
pydicom

RLE

Deflated Image Frame Compression

1.2.840.10008.1.2.8.1

pydicom

Deflated Image

Plugin requirements and limitations#

Plugin

Requires

Known limitations

pyjpegls

pyjpegls

pylibjpeg

pylibjpeg and pylibjpeg-openjpeg and/or pylibjpeg-rle

  • Maximum supported Bits Stored for JPEG 2000 is 24, however the results for 20-24 are quite poor when using lossy compression

pydicom

pydicom

  • RLE Lossless: Much slower than the other plugins