Skip to main content

Build status Test coverage PyPI versions Python versions Code style: black

pylibjpeg

A Python framework for decoding JPEG and JPEG-LS and decoding/encoding JPEG 2000 and RLE, with a focus on providing support for pydicom.

Installation

Installing the current release

pip install pylibjpeg
Installing extra requirements

The package can be installed with extra requirements to enable support for JPEG (with libjpeg), JPEG 2000 (with openjpeg) and Run-Length Encoding (RLE) (with rle), respectively:

pip install pylibjpeg[libjpeg,openjpeg,rle]

Or alternatively with just all:

pip install pylibjpeg[all]

Installing the development version

Make sure Git is installed, then

git clone https://github.com/pydicom/pylibjpeg
python -m pip install pylibjpeg

Plugins

One or more plugins are required before pylibjpeg is able to handle JPEG images or RLE datasets. To handle a given format or DICOM Transfer Syntax you first have to install the corresponding package:

Supported Image Formats

Format Decode? Encode? Plugin License Based on
JPEG, JPEG-LS and JPEG XT Yes No pylibjpeg-libjpeg GPLv3 libjpeg
JPEG 2000 Yes Yes pylibjpeg-openjpeg MIT/BSD openjpeg
High-throughput JPEG 2000 Yes No pylibjpeg-openjpeg MIT/BSD openjpeg
RLE Lossless (PackBits) Yes Yes pylibjpeg-rle MIT -

Supported DICOM Transfer Syntaxes

UID Description Plugin
1.2.840.10008.1.2.4.50 JPEG Baseline (Process 1) pylibjpeg-libjpeg
1.2.840.10008.1.2.4.51 JPEG Extended (Process 2 and 4) pylibjpeg-libjpeg
1.2.840.10008.1.2.4.57 JPEG Lossless, Non-Hierarchical (Process 14) pylibjpeg-libjpeg
1.2.840.10008.1.2.4.70 JPEG Lossless, Non-Hierarchical, First-Order Prediction
(Process 14, Selection Value 1)
pylibjpeg-libjpeg
1.2.840.10008.1.2.4.80 JPEG-LS Lossless pylibjpeg-libjpeg
1.2.840.10008.1.2.4.81 JPEG-LS Lossy (Near-Lossless) Image Compression pylibjpeg-libjpeg
1.2.840.10008.1.2.4.90 JPEG 2000 Image Compression (Lossless Only) pylibjpeg-openjpeg
1.2.840.10008.1.2.4.91 JPEG 2000 Image Compression pylibjpeg-openjpeg
1.2.840.10008.1.2.4.201 High-Throughput JPEG 2000 Image Compression (Lossless Only) pylibjpeg-openjpeg
1.2.840.10008.1.2.4.202 High-Throughput JPEG 2000 with RPCL Options Image Compression (Lossless Only) pylibjpeg-openjpeg
1.2.840.10008.1.2.4.203 High-Throughput JPEG 2000 Image Compression pylibjpeg-openjpeg
1.2.840.10008.1.2.5 RLE Lossless pylibjpeg-rle

If you're not sure what the dataset's Transfer Syntax UID is, it can be determined with:

>>> from pydicom import dcmread
>>> ds = dcmread('path/to/dicom_file')
>>> ds.file_meta.TransferSyntaxUID.name

Usage

Decoding

With pydicom

Assuming you have pydicom v2.1+ and suitable plugins installed:

from pydicom import dcmread
from pydicom.data import get_testdata_file

# With the pylibjpeg-libjpeg plugin
ds = dcmread(get_testdata_file('JPEG-LL.dcm'))
jpg_arr = ds.pixel_array

# With the pylibjpeg-openjpeg plugin
ds = dcmread(get_testdata_file('JPEG2000.dcm'))
j2k_arr = ds.pixel_array

# With the pylibjpeg-rle plugin and pydicom v2.2+
ds = dcmread(get_testdata_file('OBXXXX1A_rle.dcm'))
# pydicom defaults to the numpy handler for RLE so need
# to explicitly specify the use of pylibjpeg
ds.decompress("pylibjpeg")
rle_arr = ds.pixel_array
Standalone JPEG decoding

You can also just use pylibjpeg to decode JPEG images to a numpy ndarray, provided you have a suitable plugin installed:

from pylibjpeg import decode

# Can decode using the path to a JPG file as str or path-like
arr = decode('filename.jpg')

# Or a file-like...
with open('filename.jpg', 'rb') as f:
    arr = decode(f)

# Or bytes...
with open('filename.jpg', 'rb') as f:
    arr  = decode(f.read())

Encoding

With pydicom

Assuming you have pydicom v2.2+ and suitable plugins installed:

from pydicom import dcmread
from pydicom.data import get_testdata_file
from pydicom.uid import RLELossless

ds = dcmread(get_testdata_file("CT_small.dcm"))

# Encode in-place using RLE Lossless and update the dataset
# Updates the Pixel Data, Transfer Syntax UID and Planar Configuration
ds.compress(RLELossless)

# Save compressed
ds.save_as("CT_small_rle.dcm")

Metadata

Release files for pylibjpeg 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pylibjpeg 2.1.0
File Size Uploaded
pylibjpeg-2.1.0.tar.gz 22.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pylibjpeg 2.1.0
File Interpreter ABI Platform
pylibjpeg-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 47.5 kB

Release files / pylibjpeg-2.1.0.tar.gz

Download URL pylibjpeg-2.1.0.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2decda24982394533f16f1c6a17a6242f3391b95f69fac56c6a598a6b1362105
BLAKE2b-256 checksum
How to use checksums
1a3951c543a27592f3e9a92a3769d4cb1ef675488b79a90fef56af9071358b07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 1, 2025.

Transparency log

Release files / pylibjpeg-2.1.0-py3-none-any.whl

Download URL pylibjpeg-2.1.0-py3-none-any.whl
Size 25.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
25df9496a69e64e98c887fddee12a1271e275b5f74ba804f9bf98a08bb80993e
BLAKE2b-256 checksum
How to use checksums
3c3186c111e81c113e74ac1b0afde27755088b2db394579370c893d252d9615a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 1, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page