Skip to main content

A Python framework for decoding JPEG files, with a focus on supporting pydicom

Project description

codecov Build Status

pylibjpeg

A Python 3.6+ framework for decoding JPEG images, with a focus on providing JPEG support for pydicom.

Installation

Installing the current release

pip install pylibjpeg

Installing the development version

Make sure Git is installed, then

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

Plugins

By itself pylibjpeg is unable to decode any JPEG images, which is where the plugins come in. To support a given JPEG format or DICOM Transfer Syntax you first have to install the corresponding package:

JPEG Format

Format Decode? Encode? Plugin Based on
JPEG, JPEG-LS and JPEG XT Yes No pylibjpeg-libjpeg libjpeg

Transfer Syntax

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) Not yet supported
1.2.840.10008.1.2.4.91 JPEG 2000 Image Compression Not yet supported

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

With pydicom

Assuming you already have pydicom installed:

from pydicom import dcmread
from pydicom.data import get_testdata_file

# With the pylibjpeg-libjpeg plugin installed
import pylibjpeg

ds = dcmread(get_testdata_file('JPEG-LL.dcm'))
arr = ds.pixel_array

For datasets with multiple frames you can reduce your memory usage by processing each frame separately using the generate_frames() generator function:

from pydicom import dcmread
from pydicom.data import get_testdata_file

from pylibjpeg import generate_frames

ds = dcmread(get_testdata_file('color3d_jpeg_baseline.dcm'))
frames = generate_frames(ds)
arr = next(frames)

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 pathlike
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())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylibjpeg-1.0.0.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

pylibjpeg-1.0.0-py2.py3-none-any.whl (31.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pylibjpeg-1.0.0.tar.gz.

File metadata

  • Download URL: pylibjpeg-1.0.0.tar.gz
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9

File hashes

Hashes for pylibjpeg-1.0.0.tar.gz
Algorithm Hash digest
SHA256 37f7385864d77f32d5dd5ef150bea09bf70fa28998a50bc43a10a2bdf2e49836
MD5 6c8062ae2ae6f659db5fdd9639589149
BLAKE2b-256 706f5ddbab7592c90faca9dfdf69f42926e7af3617523c145fed21363a471de6

See more details on using hashes here.

File details

Details for the file pylibjpeg-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pylibjpeg-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 31.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9

File hashes

Hashes for pylibjpeg-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c2009e77570d1eb60c63a43923f3632605aeb1c716f59c4b885830874992f97e
MD5 63ac54af81807fd00e1c8e6750f5408c
BLAKE2b-256 0573a2642b77626cdf43c7d45e91bd403349ada93c0700da461663cf84f4b99f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page