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), PixarLog, Jetraw, DICOM RLE, CCITT (RLE, T.4 and T.6), PackBits, Packed Integers (TIFF, MONO p and packed), 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.3.6

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.12, 3.14.3 64-bit

  • numpy 2.4.2

  • 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.3.6

  • Pass 8575 tests.

  • Add CCITTRLE, CCITTFAX3 and CCITTFAX4 codecs (decode only).

  • Implement packints_encode function.

  • Support lerc subcodec in tiff_encode function.

  • Support packed integers, ccitt and pixarlog compression in TIFF codec.

  • Support bitorder option in PACKINTS codec.

  • Support rounding in BFLOAT16 codec.

  • Support more BMP types.

  • Update PCODEC to new API.

  • Fix buffer overflows in third-party code.

  • Fix code review issues.

2026.1.14

  • 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, ccittfax3, ccittfax4, ccittrle, dds, dicomrle, eer, jpegsof3, and lzo codecs are currently decode-only.

The brunsli codec is distributed as source code only because the underlying library is 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, crackle, 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 dicomrle_encode
>>> dicomrle_encode(array)
Traceback (most recent call last):
 ...
NotImplementedError: dicomrle_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.3.6.tar.gz (9.6 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.3.6-cp314-cp314t-win_arm64.whl (15.9 MB view details)

Uploaded CPython 3.14tWindows ARM64

imagecodecs-2026.3.6-cp314-cp314t-win_amd64.whl (20.2 MB view details)

Uploaded CPython 3.14tWindows x86-64

imagecodecs-2026.3.6-cp314-cp314t-win32.whl (16.3 MB view details)

Uploaded CPython 3.14tWindows x86

imagecodecs-2026.3.6-cp314-cp314t-manylinux_2_28_x86_64.whl (30.0 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.28+ x86-64

imagecodecs-2026.3.6-cp314-cp314t-manylinux_2_28_aarch64.whl (29.6 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.28+ ARM64

imagecodecs-2026.3.6-cp314-cp314t-macosx_11_0_arm64.whl (12.0 MB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

imagecodecs-2026.3.6-cp314-cp314t-macosx_10_15_x86_64.whl (14.3 MB view details)

Uploaded CPython 3.14tmacOS 10.15+ x86-64

imagecodecs-2026.3.6-cp311-abi3-win_arm64.whl (15.2 MB view details)

Uploaded CPython 3.11+Windows ARM64

imagecodecs-2026.3.6-cp311-abi3-win_amd64.whl (19.2 MB view details)

Uploaded CPython 3.11+Windows x86-64

imagecodecs-2026.3.6-cp311-abi3-win32.whl (15.6 MB view details)

Uploaded CPython 3.11+Windows x86

imagecodecs-2026.3.6-cp311-abi3-manylinux_2_28_x86_64.whl (26.5 MB view details)

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

imagecodecs-2026.3.6-cp311-abi3-manylinux_2_28_aarch64.whl (25.6 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ ARM64

imagecodecs-2026.3.6-cp311-abi3-macosx_11_0_arm64.whl (11.7 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

imagecodecs-2026.3.6-cp311-abi3-macosx_10_15_x86_64.whl (14.0 MB view details)

Uploaded CPython 3.11+macOS 10.15+ x86-64

File details

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

File metadata

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

File hashes

Hashes for imagecodecs-2026.3.6.tar.gz
Algorithm Hash digest
SHA256 471b8a4d1b3843cbf7179b45f7d7261f0c0b28809efc1ca6c47822477b143b85
MD5 88de5dc8b93013817ffc88c89c972d78
BLAKE2b-256 3b8ddc18623e5e926ad53c626e128c8baaf4ec42e41029cf0a07381cfef79289

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for imagecodecs-2026.3.6-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 a2363c64e346cee4136f02a207b1b645729142f5260d122ddc3d5ff9e32ac6b1
MD5 0819fdc9b3cf7266c91784a5d97793a1
BLAKE2b-256 9c063a5fe853e4df9a3655f8be81c1eb48013aab282c1557341b8634dd718e32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for imagecodecs-2026.3.6-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 1b810efeeb06bdcca07ae410a81bdb5eb9fb38f91689baf0f0b75783f5119a40
MD5 26b8f31b1a5b3d5a6aa6a6e92017dd3e
BLAKE2b-256 d513d0e09d8aaafe6fac1aa1bd8c0dcc0f024998ea4a23477128db14a085b4cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for imagecodecs-2026.3.6-cp314-cp314t-win32.whl
Algorithm Hash digest
SHA256 65110ff30723a6e0b79c6c74ff52909a34b131366c4f76b1b68084cca5fcd982
MD5 d667ce892ae9fc94b7e82b5dd77eff00
BLAKE2b-256 ac961474c0e242fb11d68304f858298971370fdfcecc404dbd9993a3ea449b4f

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.3.6-cp314-cp314t-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.3.6-cp314-cp314t-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 39fcf671537cc92dd24ba4dcba257d8aa47e6f58018e839a5216c626f03d4126
MD5 5757fe742b19e7b2e54f4002898ef0e1
BLAKE2b-256 0c8ca1b433418306636fc22a94b669d7ebbbde8e3b26aef7d693c08f9f8a65af

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.3.6-cp314-cp314t-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.3.6-cp314-cp314t-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 16fd83dd25d9c888317bc8cbbc5d7490b78c84c58275d80fb71ea7b28645276a
MD5 d355a16d0ddb721024f7a98498310a90
BLAKE2b-256 29d3f0a71c797f836021241500d4a459b0f93317f2b5c9bcc39fb1eaa50e01ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for imagecodecs-2026.3.6-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6efa104ce600f61fef03a43daab34fe2953c8adb4e4ee6eb9544825f5361e5ab
MD5 e2331bf840688551af8e0b69495d0c5a
BLAKE2b-256 18d94750fb9739d474e399fa566b3a5c7033f2c9c0078bc869473b23d3e0d4b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for imagecodecs-2026.3.6-cp314-cp314t-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 ea2cd774854a3bfe1dc9508f98907edc877c02a78642ab371adbdec65a8865cc
MD5 cbee8463bae2c2714a1e7e338fbb419b
BLAKE2b-256 a30bba7ca5a14cf2ff744c47898ab9e98b6b96b364bce1459afcab5f4e5ea2bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for imagecodecs-2026.3.6-cp311-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 fc4856913be6c8b3861223158920d934a0ae203149a435f585622dbbff8ed696
MD5 68241747836bed0191ea15e5b896f7c3
BLAKE2b-256 c0c794e930cef9e0a29a2df5e3ba3bacd2c2f1e34ca373fe48624b64af8ae91c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for imagecodecs-2026.3.6-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e8fba5b9ac7be109ed35070208bc1683fa17cc381ed9535a4eae200c6d883bd8
MD5 185f2819da7f2a6ba51cdfd432604b16
BLAKE2b-256 22c72b37a7fe9a2eb21011e50f046d62e68ac4e0f8d6ad94d7a10e9f8e8d685f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for imagecodecs-2026.3.6-cp311-abi3-win32.whl
Algorithm Hash digest
SHA256 c972a45dfee1befbac048ba3492607003e9a185811e8febdc1ed531d48c07e75
MD5 6277087c42fa719cccebe225e3abbb7b
BLAKE2b-256 e8a7e3a89b2c516eaca7446e8f1335daeec90764b50888af5e073a2b6a987fcf

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.3.6-cp311-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.3.6-cp311-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e30a14aa2e1c6c90e00375292726486c1d90bf003b1414d608ea4d1f62fd8a79
MD5 300b57cf065f285d4024dac085f268b6
BLAKE2b-256 8f2993ea9cbab7f57b4e60480c51fc51d8e138e399d11797c981d5f6e79f9832

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.3.6-cp311-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.3.6-cp311-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 30fa140bb1a112a889926af36977214ed52a22e4557356043259b5e2f79cfba5
MD5 44067ff1e3b9c12615724415e3c2a201
BLAKE2b-256 45faf67c4e644fdf06503e120f9d1c8d8654b99066dea7093a674b67704fa4a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for imagecodecs-2026.3.6-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e64037f22980a211b17bf6bdf03f14ff459a7432eec24f7a58c342f6992132fa
MD5 bf5f8f729acb9fe20826c3eb6962d40b
BLAKE2b-256 428436c38a82f033ffbc9e706dad32be7148f130fc00e7bb417ab60e063897a0

See more details on using hashes here.

File details

Details for the file imagecodecs-2026.3.6-cp311-abi3-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for imagecodecs-2026.3.6-cp311-abi3-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 44cfb3b609d941014f8ac7cf8611b15ccfd7119443bbb6b5e53916b242d31f9e
MD5 94368acb4d4a904676476329c7d2f209
BLAKE2b-256 f3db873d063c99a726d772bf6f076288da59bb12e9f2af3518c2e4de5fde234d

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