Skip to main content

A Python wrapper for openjpeg, with a focus on use as a plugin for for pylibjpeg

Project description

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

pylibjpeg-openjpeg

A Python 3.8+ wrapper for openjpeg, with a focus on use as a plugin for pylibjpeg.

Linux, OSX and Windows are all supported.

Installation

Dependencies

NumPy

Installing the current release

python -m pip install -U pylibjpeg-openjpeg

Installing the development version

Make sure Python, Git and CMake are installed. For Windows, you also need to install Microsoft's C++ Build Tools.

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

Supported JPEG Formats

Decoding

ISO/IEC Standard ITU Equivalent JPEG Format
15444-1 T.800 JPEG 2000

Encoding

Encoding of NumPy ndarrays is supported for the following:

  • Array dtype: bool, uint8, int8, uint16, int16, uint32 and int32 (1-24 bit-depth only)
  • Array shape: (rows, columns) and (rows, columns, planes)
  • Number of rows/columns: up to 65535
  • Number of planes: 1, 3 or 4

Transfer Syntaxes

UID Description
1.2.840.10008.1.2.4.90 JPEG 2000 Image Compression (Lossless Only)
1.2.840.10008.1.2.4.91 JPEG 2000 Image Compression
1.2.840.10008.1.2.4.201 High-Throughput JPEG 2000 Image Compression (Lossless Only)
1.2.840.10008.1.2.4.202 High-Throughput JPEG 2000 with RPCL Options Image Compression (Lossless Only)
1.2.840.10008.1.2.4.203 High-Throughput JPEG 2000 Image Compression

Usage

With pylibjpeg and pydicom

from pydicom import dcmread
from pydicom.data import get_testdata_file

ds = dcmread(get_testdata_file('JPEG2000.dcm'))
arr = ds.pixel_array

Standalone JPEG decoding

You can also decode JPEG 2000 images to a numpy ndarray:

from openjpeg import decode

with open('filename.j2k', 'rb') as f:
    # Returns a numpy array
    arr = decode(f)

# Or simply...
arr = decode('filename.j2k')

Standalone JPEG encoding

Lossless encoding of RGB with multiple-component transformation:

import numpy as np
from openjpeg import encode_array

arr = np.random.randint(low=0, high=65536, size=(100, 100, 3), dtype="uint8")
encode_array(arr, photometric_interpretation=1)  # 1: sRGB

Lossy encoding of a monochrome image using compression ratios:

import numpy as np
from openjpeg import encode_array

arr = np.random.randint(low=-2**15, high=2**15, size=(100, 100), dtype="int8")
# You must determine your own values for `compression_ratios`
#   as these are for illustration purposes only
encode_array(arr, compression_ratios=[5, 2])

Lossy encoding of a monochrome image using peak signal-to-noise ratios:

import numpy as np
from openjpeg import encode_array

arr = np.random.randint(low=-2**15, high=2**15, size=(100, 100), dtype="int8")
# You must determine your own values for `signal_noise_ratios`
#   as these are for illustration purposes only
encode_array(arr, signal_noise_ratios=[50, 80, 100])

See the docstring for the encode_array() function for full details.

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_openjpeg-2.2.1.tar.gz (2.0 MB view hashes)

Uploaded Source

Built Distributions

pylibjpeg_openjpeg-2.2.1-cp312-cp312-win_amd64.whl (333.1 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

pylibjpeg_openjpeg-2.2.1-cp312-cp312-win32.whl (309.4 kB view hashes)

Uploaded CPython 3.12 Windows x86

pylibjpeg_openjpeg-2.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pylibjpeg_openjpeg-2.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

pylibjpeg_openjpeg-2.2.1-cp312-cp312-macosx_12_0_x86_64.whl (405.6 kB view hashes)

Uploaded CPython 3.12 macOS 12.0+ x86-64

pylibjpeg_openjpeg-2.2.1-cp312-cp312-macosx_12_0_arm64.whl (372.2 kB view hashes)

Uploaded CPython 3.12 macOS 12.0+ ARM64

pylibjpeg_openjpeg-2.2.1-cp311-cp311-win_amd64.whl (334.0 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

pylibjpeg_openjpeg-2.2.1-cp311-cp311-win32.whl (309.8 kB view hashes)

Uploaded CPython 3.11 Windows x86

pylibjpeg_openjpeg-2.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pylibjpeg_openjpeg-2.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

pylibjpeg_openjpeg-2.2.1-cp311-cp311-macosx_12_0_x86_64.whl (407.0 kB view hashes)

Uploaded CPython 3.11 macOS 12.0+ x86-64

pylibjpeg_openjpeg-2.2.1-cp311-cp311-macosx_12_0_arm64.whl (372.8 kB view hashes)

Uploaded CPython 3.11 macOS 12.0+ ARM64

pylibjpeg_openjpeg-2.2.1-cp310-cp310-win_amd64.whl (333.7 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

pylibjpeg_openjpeg-2.2.1-cp310-cp310-win32.whl (310.4 kB view hashes)

Uploaded CPython 3.10 Windows x86

pylibjpeg_openjpeg-2.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pylibjpeg_openjpeg-2.2.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pylibjpeg_openjpeg-2.2.1-cp310-cp310-macosx_12_0_x86_64.whl (406.8 kB view hashes)

Uploaded CPython 3.10 macOS 12.0+ x86-64

pylibjpeg_openjpeg-2.2.1-cp310-cp310-macosx_12_0_arm64.whl (372.9 kB view hashes)

Uploaded CPython 3.10 macOS 12.0+ ARM64

pylibjpeg_openjpeg-2.2.1-cp39-cp39-win_amd64.whl (333.7 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

pylibjpeg_openjpeg-2.2.1-cp39-cp39-win32.whl (310.3 kB view hashes)

Uploaded CPython 3.9 Windows x86

pylibjpeg_openjpeg-2.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pylibjpeg_openjpeg-2.2.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

pylibjpeg_openjpeg-2.2.1-cp39-cp39-macosx_12_0_x86_64.whl (406.8 kB view hashes)

Uploaded CPython 3.9 macOS 12.0+ x86-64

pylibjpeg_openjpeg-2.2.1-cp39-cp39-macosx_12_0_arm64.whl (373.0 kB view hashes)

Uploaded CPython 3.9 macOS 12.0+ ARM64

pylibjpeg_openjpeg-2.2.1-cp38-cp38-win_amd64.whl (333.9 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

pylibjpeg_openjpeg-2.2.1-cp38-cp38-win32.whl (310.4 kB view hashes)

Uploaded CPython 3.8 Windows x86

pylibjpeg_openjpeg-2.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pylibjpeg_openjpeg-2.2.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

pylibjpeg_openjpeg-2.2.1-cp38-cp38-macosx_12_0_x86_64.whl (406.7 kB view hashes)

Uploaded CPython 3.8 macOS 12.0+ x86-64

pylibjpeg_openjpeg-2.2.1-cp38-cp38-macosx_12_0_arm64.whl (372.9 kB view hashes)

Uploaded CPython 3.8 macOS 12.0+ ARM64

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