JPEG 2000 libraries for Python
All three libraries use OpenJPEG for the actual decoding and encoding:
- Pillow opens JPEG 2000 like any other image. Pick it for simple conversion and editing of 8-bit images. The wheels on PyPI include OpenJPEG.
- glymur gives full access to JP2 boxes (XML, XMP, ICC, GeoJP2), reads reduced resolutions and regions with NumPy slicing, and writes with every OpenJPEG option. Pick it for scientific, geospatial and archival files.
- imagecodecs encodes and decodes NumPy arrays in memory, including 16-bit data. Pick it in scientific pipelines, and with tifffile or zarr.
For DICOM, pydicom decodes JPEG 2000 pixel data with pylibjpeg-openjpeg or Pillow. OpenCV also reads and writes .jp2 with cv2.imread / cv2.imwrite when built with OpenJPEG.
- glymur glymur is a Python interface to OpenJPEG for reading and writing JPEG 2000 as NumPy arrays. How to read JP2 files, read reduced resolutions and regions.
- imagecodecs imagecodecs encodes and decodes JPEG 2000 NumPy arrays in Python with OpenJPEG. How to install it, decode JP2 and J2K bytes, encode lossless.
- Pillow Pillow reads and writes JPEG 2000 in Python using OpenJPEG. How to convert JP2 to PNG, save lossy and lossless JPEG 2000, decode at reduced resolution.