Skip to main content

Image transformation, compression, and decompression codecs

Project description

Imagecodecs is a Python library that provides block-oriented, in-memory buffer transformation, compression, and decompression functions for use in tifffile, liffile, czifile, zarr, and other scientific image input/output packages.

Decode and/or encode functions are implemented for Zlib (DEFLATE), GZIP, LZMA, ZStandard (ZSTD), Blosc, Brotli, Snappy, BZ2, LZ4, LZ4F, LZ4HC, LZ4H5, LZW, LZO, LZF, LZFSE, LZHAM, PGLZ (PostgreSQL LZ), RCOMP (Rice), ZFP, SZ3, Meshopt, Pcodec, SPERR, AEC, SZIP, LERC, EER, NPY, BCn, DDS, BMP, PNG, APNG, GIF, TIFF, WebP, JPEG (2 to 16-bit), Lossless JPEG (LJPEG, LJ92, JPEGLL), JPEG 2000 (JP2, J2K), High-throughput JPEG 2000 (HTJ2K, JPH), JPEG LS, JPEG XL, JPEG XS, JPEG XR (WDP, HD Photo), Ultra HDR (JPEG_R), MOZJPEG, AVIF, HEIF, QOI, RGBE (HDR), Jetraw, DICOM RLE, PackBits, Packed Integers, Delta, XOR Delta, Floating Point Predictor, Bitorder reversal, Byteshuffle, Bitshuffle, Float24 (24-bit floating point), Bfloat16 (brain floating point), Quantize (Scale, BitGroom, BitRound, GranularBR), and CMS (color space transformations). Checksum functions are implemented for CRC-32, Adler-32, Fletcher-32, and Jenkins lookup3.

Author:

Christoph Gohlke

License:

BSD-3-Clause

Version:

2026.1.14

DOI:

10.5281/zenodo.6915978

Quickstart

Install the imagecodecs package and all dependencies from the Python Package Index:

python -m pip install -U "imagecodecs[all]"

Imagecodecs is also available in other package repositories such as Anaconda, MSYS2, and MacPorts.

See Requirements and Notes for building from source.

See Examples for using the programming interface.

Source code and support are available on GitHub.

Requirements

This revision was tested with the following requirements and dependencies (other versions may work):

  • CPython 3.11.9, 3.12.10, 3.13.11, 3.14.2 64-bit

  • numpy 2.4.1

  • numcodecs 0.16.5 (optional, for Zarr file format 2 compatible codecs)

Build requirements:

Unmaintained or discontinued build requirements:

Vendored requirements:

Test requirements:

Revisions

2026.1.14

  • Pass 8281 tests.

  • Add tiff_encode function.

  • Add extra options for HTJ2K (#134).

  • Add linear RGB option to cms_profile.

  • Change ZSTD default compression level to 3.

2026.1.1

  • Enforce positional-only and keyword-only parameters (breaking).

  • Base numcodecs.Jpeg on JPEG8 codec (breaking).

  • Add HTJ2K codec based on OpenJPH library (#125).

  • Add MESHOPT codec based on meshoptimizer library.

  • Fix decoding concatenated ZStandard frames.

  • Fix potential issues in TIFF and WEBP codecs.

  • Fix pyi stub file.

  • Change default Brotli compression level to 4.

  • Use Brotli streaming API for decoding.

  • Enable decoding UltraHDR to uint16.

  • Tweak memory allocation and reallocation strategies.

  • Use fused types.

  • Improve code quality.

2025.11.11

  • Fix EER superresolution decoding (breaking; see tifffile #313).

  • Add option to eer_decode to add to uint16 array.

  • Add option to specify CICP/NCLX parameters in avif_encode (#131).

  • Add BFLOAT16 codec.

  • Build ABI3 wheels.

  • Require Cython >= 3.2.

  • Deprecate Python 3.11.

2025.8.2

  • Fix szip_encode default output buffer might be too small (#128).

  • Fix minor bugs in LZ4H5 codec (#127).

  • Avoid grayscale-to-RGB conversions in AVIF codecs.

  • Improve AVIF error messages.

  • Add flag for free-threading compatibility (#113).

  • Do not use zlib uncompress2, which is not available on manylinux.

  • Do not build unstable BRUNSLI, PCODEC, SPERR, and SZ3 codecs.

  • Require libavif >= 1.3 and Cython >= 3.1.

  • Support Python 3.14 and 3.14t.

  • Drop support for Python 3.10 and PyPy.

2025.3.30

  • Fix some codecs for use with Zarr 3, zarr_format=2 (#123).

  • Fix LZ4H5 codec when block size is less than compressed size (#126).

  • Fix pglz_compress is not thread-safe.

  • Set __module__ attribute on public objects.

  • Drop support for Python 3.9, deprecate Python 3.10.

2024.12.30

Refer to the CHANGES file for older revisions.

Objectives

Many scientific image storage formats, such as TIFF, CZI, XLIF, DICOM, HDF, and Zarr are containers that store numerous small data segments (chunks, tiles, stripes). These segments are encoded using various compression and pre-filtering methods. Metadata common to all data segments are typically stored separately from the segments.

The purpose of the Imagecodecs library is to support Python modules in encoding and decoding such data segments. The specific aims are:

  • Provide functions for encoding and decoding small image data segments in-memory (as opposed to in-file) from and to bytes or numpy arrays for many compression and filtering methods.

  • Support image formats and compression methods that are not available elsewhere in the Python ecosystem.

  • Reduce the runtime dependency on numerous, large, inapt, or unmaintained Python packages. The Imagecodecs package only depends on numpy.

  • Implement codecs as Cython wrappers of third-party libraries with a C API and permissive license if available; otherwise use own C library. Provide Cython definition files for the wrapped C libraries.

  • Release the Python global interpreter lock (GIL) during extended native/C function calls for multi-threaded use.

Accessing parts of large data segments and reading metadata from segments are outside the scope of this library.

Notes

This library is largely a work in progress.

The API is not stable yet and might change between revisions.

Python <= 3.10 is no longer supported. 32-bit versions are deprecated.

Works on little-endian platforms only.

Supported platforms are win_amd64, win_arm64, win32, macosx_x86_64, macosx_arm64, manylinux_x86_64, and manylinux_aarch64.

Wheels may not be available for all platforms and all releases.

Not all features are available on all platforms.

The bcn, dds, dicomrle, eer, lzo, packints, and jpegsof3 codecs are currently decode-only.

The brunsli and pcodec codecs are distributed as source code only because the underlying libraries are unstable.

The heif, jetraw, and jpegxs codecs are distributed as source code only due to license and possible patent usage issues.

The latest Microsoft Visual C++ Redistributable for Visual Studio 2017-2026 is required on Windows.

Refer to the imagecodecs/licenses folder for 3rd-party library licenses.

This software is based in part on the work of the Independent JPEG Group.

Update pip and setuptools to the latest version before installing imagecodecs:

python -m pip install -U pip setuptools wheel Cython.

When building against libjpeg or libjpeg_turbo < 3, set the environment variable IMAGECODECS_JPEG8_LEGACY=1 to enable legacy API support.

Before building imagecodecs from source code, install required tools and libraries. For example, on latest Ubuntu Linux distributions:

sudo apt-get install build-essential python3-dev cython3 python3-pip python3-setuptools python3-wheel python3-numpy libdeflate-dev libjpeg-dev libjxr-dev liblcms2-dev liblz4-dev liblerc-dev liblzma-dev libopenjp2-7-dev libpng-dev libtiff-dev libwebp-dev libz-dev libzstd-dev

To build and install imagecodecs from source code, run:

python -m pip install .

Many extensions are disabled by default when building from source.

To define which extensions are built, or to modify build settings such as library names and compiler arguments, provide a imagecodecs_distributor_setup.customize_build function, which is imported and executed during setup. See setup.py for pre-defined customize_build functions.

Other projects providing imaging or compression codecs: stdlib-zlib, stdlib-bz2, stdlib-lzma, backports.lzma, python-lzo, python-lzw, python-lerc, wavpack-numcodecs, packbits, isa-l.igzip, fpzip, libmng, openexr, openzl, openhtj2k, pyjetraw, tinyexr, pytinyexr, pyroexr, jasper, libjpeg (gpl), pylibjpeg, pylibjpeg-libjpeg (gpl), pylibjpeg-openjpeg, pylibjpeg-rle, glymur, pyheif, pyrus-cramjam, pylzham, brieflz, quicklz (gpl), lzo (gpl), nvjpeg, nvjpeg2k, pyturbojpeg, ccsds123, lpc-rice, compression-algorithms, compressonator, wuffs, tinydng, grok (agpl), mafisc, b3d, fo-dicom.codecs, jpegli, hdf5plugin.

Examples

Import the JPEG2K codec:

>>> from imagecodecs import (
...     jpeg2k_encode,
...     jpeg2k_decode,
...     jpeg2k_check,
...     jpeg2k_version,
...     JPEG2K,
... )

Check that the JPEG2K codec is available in the imagecodecs build:

>>> JPEG2K.available
True

Print the version of the JPEG2K codec’s underlying OpenJPEG library:

>>> jpeg2k_version()
'openjpeg 2.5.4'

Encode a numpy array in lossless JP2 format:

>>> import numpy
>>> array = numpy.random.randint(100, 200, (256, 256, 3), numpy.uint8)
>>> encoded = jpeg2k_encode(array, level=0)
>>> bytes(encoded[:12])
b'\x00\x00\x00\x0cjP  \r\n\x87\n'

Check that the encoded bytes likely contain a JPEG 2000 stream:

>>> jpeg2k_check(encoded)
True

Decode the JP2 encoded bytes to a numpy array:

>>> decoded = jpeg2k_decode(encoded)
>>> numpy.array_equal(decoded, array)
True

Decode the JP2 encoded bytes to an existing numpy array:

>>> out = numpy.empty_like(array)
>>> _ = jpeg2k_decode(encoded, out=out)
>>> numpy.array_equal(out, array)
True

Not all codecs are fully implemented, raising exceptions at runtime:

>>> from imagecodecs import packints_encode
>>> packints_encode(array, 8)
Traceback (most recent call last):
 ...
NotImplementedError: packints_encode

Write the numpy array to a JP2 file:

>>> from imagecodecs import imwrite, imread
>>> imwrite('_test.jp2', array)

Read the image from the JP2 file as numpy array:

>>> image = imread('_test.jp2')
>>> numpy.array_equal(image, array)
True

Create a JPEG 2000 compressed Zarr array:

>>> import zarr
>>> import numcodecs
>>> from imagecodecs.numcodecs import Jpeg2k
>>> numcodecs.register_codec(Jpeg2k)
>>> zarr.zeros(
...     (4, 5, 512, 512, 3),
...     chunks=(1, 1, 256, 256, 3),
...     dtype='u1',
...     compressor=Jpeg2k(),
...     zarr_format=2,
... )
<...Array ...(4, 5, 512, 512, 3) ...uint8>

Access image data in a sequence of JP2 files via tifffile.FileSequence and dask.array:

>>> import tifffile
>>> import dask.array
>>> def jp2_read(filename):
...     with open(filename, 'rb') as fh:
...         data = fh.read()
...     return jpeg2k_decode(data)
...
>>> with tifffile.FileSequence(jp2_read, '*.jp2') as ims:
...     with ims.aszarr() as store:
...         dask.array.from_zarr(store)
...
dask.array<from-zarr, shape=(1, 256, 256, 3)...chunksize=(1, 256, 256, 3)...

Write the Zarr store to a fsspec ReferenceFileSystem in JSON format and open it as a Zarr array:

>>> store.write_fsspec(
...     'temp.json', url='file://', codec_id='imagecodecs_jpeg2k'
... )
>>> from kerchunk.utils import refs_as_store
>>> zarr.open(refs_as_store('temp.json'), mode='r')
<Array <FsspecStore(ReferenceFileSystem, /)> shape=(1, 256, 256, 3) dtype=uint8>

View the image in the JP2 file from the command line:

python -m imagecodecs _test.jp2

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

imagecodecs-2026.1.14.tar.gz (9.5 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

imagecodecs-2026.1.14-cp314-cp314t-win_arm64.whl (17.5 MB view details)

Uploaded CPython 3.14tWindows ARM64

imagecodecs-2026.1.14-cp314-cp314t-win_amd64.whl (22.5 MB view details)

Uploaded CPython 3.14tWindows x86-64

imagecodecs-2026.1.14-cp314-cp314t-win32.whl (17.9 MB view details)

Uploaded CPython 3.14tWindows x86

imagecodecs-2026.1.14-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (28.0 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

imagecodecs-2026.1.14-cp314-cp314t-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (27.4 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

imagecodecs-2026.1.14-cp314-cp314t-macosx_11_0_arm64.whl (11.0 MB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

imagecodecs-2026.1.14-cp314-cp314t-macosx_10_15_x86_64.whl (13.2 MB view details)

Uploaded CPython 3.14tmacOS 10.15+ x86-64

imagecodecs-2026.1.14-cp311-abi3-win_arm64.whl (16.9 MB view details)

Uploaded CPython 3.11+Windows ARM64

imagecodecs-2026.1.14-cp311-abi3-win_amd64.whl (21.5 MB view details)

Uploaded CPython 3.11+Windows x86-64

imagecodecs-2026.1.14-cp311-abi3-win32.whl (17.2 MB view details)

Uploaded CPython 3.11+Windows x86

imagecodecs-2026.1.14-cp311-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (24.7 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

imagecodecs-2026.1.14-cp311-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (23.7 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

imagecodecs-2026.1.14-cp311-abi3-macosx_11_0_arm64.whl (10.7 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

imagecodecs-2026.1.14-cp311-abi3-macosx_10_14_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.11+macOS 10.14+ x86-64

File details

Details for the file imagecodecs-2026.1.14.tar.gz.

File metadata

  • Download URL: imagecodecs-2026.1.14.tar.gz
  • Upload date:
  • Size: 9.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for imagecodecs-2026.1.14.tar.gz
Algorithm Hash digest
SHA256 e37ef5116d41ba90b1c9d1d7121846671fd65c271f0c15ef24208353fa79b283
MD5 4f1e3ed113e8c29cdd50fa910c7be68c
BLAKE2b-256 af75cedaa3dba300df85712515b9c9e13d848ea9557b796b6c44b50bd361571e

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.1.14-cp314-cp314t-win_arm64.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.1.14-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 d4c19df6142481d2fda62d91542c078aecd647f120da52cc79019ed6938e587d
MD5 f56b051746a8e114f5147ac2c395d098
BLAKE2b-256 04f72dfe80928bf0c6c6e7411954fa008a71d0b08e72fe1028fe9a8a8116588a

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.1.14-cp314-cp314t-win_amd64.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.1.14-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 9b11ced125e7b8da2a9d1a30505827cdb27f7023ccee4cd4cc5e3b352dce8574
MD5 6b3f9ec0b48430430cf6644422c8ce81
BLAKE2b-256 b335cb1fc0ce35dd61475672af65607fe2c3cc30d7844d617067a3e649b8366e

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.1.14-cp314-cp314t-win32.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.1.14-cp314-cp314t-win32.whl
Algorithm Hash digest
SHA256 ae422def59fab163ba0cb79470e10aa64b8a62b29e74d50ecd0edab4349444c2
MD5 95b39a5ab22663ad68424770e8e852dd
BLAKE2b-256 ad58b098490e93435ef4311c473e30588e80f966f6d676f1343804f8ab3fcff1

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.1.14-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.1.14-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a6819b8365cf28e2a85dcb04fb9c1f1acb63cf5da61495910cd751a7e2548e1d
MD5 147be29d2870d1ec0e8f965e06e6d777
BLAKE2b-256 6ef1f39cacf55d5e7175f1e7b5222178e7c56d6ca1a49e61011adb1150d85aec

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.1.14-cp314-cp314t-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.1.14-cp314-cp314t-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ca3325e68dffeb29383f4a28957ac61d3c0ade1b244ebf70797bdaf009ad1578
MD5 299b2ad7bcac08873759b4d258d9ea2e
BLAKE2b-256 e1e90400722f5bdaaa9bc13ad77c78606cfb767f2b609cb136cc81d81c380807

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.1.14-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.1.14-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c189f5d842f1f2524c27c307220c5f2cf201af44dab74b1f7476645f72eb2e87
MD5 337431836748c382de130f09e599a1cb
BLAKE2b-256 bbda9fb0e446f5af6fa21f44a1f1d4950e538345d7e8931b5983a543a24b9c38

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.1.14-cp314-cp314t-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.1.14-cp314-cp314t-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 455915b32ae1ecccaeb9dad32ad1499aa2e6928b6b853e3635cb32af9aa56857
MD5 1b70bbf18ae96ee3628f51270e6cada2
BLAKE2b-256 4ea3f92989c2de762ee4db9f5454bbafa540cfa13d28006b4aeb01936f9a4a8a

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.1.14-cp311-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.1.14-cp311-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 2a6102f3b99c66e090a619f8a0204e6e95c01399854ffa09e4a9de476dc1671a
MD5 cd6b871869554548bbaec4463acd4ffb
BLAKE2b-256 546e86fa1a07aee2ea39acfa04e372a144a72b4cdc80f40a11a3ee312c12d312

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.1.14-cp311-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.1.14-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 13ec4659d05010aa072644f100d0e1e1fcc61d7eaa960923b8216272682e6c9a
MD5 2078c2cd722d5ef4db7d5a5b480982b0
BLAKE2b-256 b622ae01473653dbad9e10a1632b5d8ae6473de0f3ec2b82c912836661d501a9

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.1.14-cp311-abi3-win32.whl.

File metadata

  • Download URL: imagecodecs-2026.1.14-cp311-abi3-win32.whl
  • Upload date:
  • Size: 17.2 MB
  • Tags: CPython 3.11+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for imagecodecs-2026.1.14-cp311-abi3-win32.whl
Algorithm Hash digest
SHA256 6bbf7defac9f71e0401305440f7e94160201789e03ee75e6e5709bc904742429
MD5 d3421ff03df22cbcb4b36c8f3506ad1c
BLAKE2b-256 81aff03fa2a60617a46814fea5523f8d53a703aabbb316e029b21efe8fe04f9f

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.1.14-cp311-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.1.14-cp311-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8a78451926905459f42e827c207d80e1601abf68eaf0e38fd65ddd3c346d1f47
MD5 64afdb244eac17f43d647281c553bdba
BLAKE2b-256 02e18a299b91a4abee7c299c0c6625f9c0985c623fd4b6b41b5a5fe92508bb18

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.1.14-cp311-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.1.14-cp311-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4e92f8b3bddf632c23d3a832f35e5a2c2326eb0e2ae1ebce419789cce63e5c30
MD5 b8e875a199b72f7cb03a5b32201d12e2
BLAKE2b-256 84b448fc1a9b2379941a752d046b6d9217a1e82c09ed11184a18245cbb0d9c8b

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.1.14-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.1.14-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bd72bdff628d6c32c71f086e488f483abbf84816b05d439964d980af49f2a9c5
MD5 e09847a92584c9c3a787c358b79c2830
BLAKE2b-256 267971780373cef2ec5d9d2f111010ff0a16de0788fdc9a8f26f3cce05d0ed38

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.1.14-cp311-abi3-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.1.14-cp311-abi3-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 b94c57922816eb025d443f4594f1235d80f0f56b4b48aa9b60bf9d679ea49415
MD5 b0ba74d77c851b4813498514aaebf2b7
BLAKE2b-256 f6b2c36b8633c3303ed8d80c8d8490c8488baa7f9e6f46fd11688cb9e68eae5e

See more details on using hashes here.

Supported by

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