glymur
raw JSON → 0.14.7 verified Fri May 01 auth: no python
Python library for reading and writing JPEG 2000 files, wrapping the OpenJPEG library. Current version 0.14.7, requires Python >=3.11, release cadence irregular.
pip install glymur Common errors
error ImportError: libopenjp2.so.7: cannot open shared object file ↓
cause OpenJPEG library not installed or not in library path.
fix
Install OpenJPEG: apt install libopenjp2-7-dev (Linux) or brew install openjpeg (macOS) or conda install openjpeg.
error AttributeError: 'Jp2k' object has no attribute 'read' ↓
cause Use of deprecated read() method removed in newer versions.
fix
Use direct indexing: data = jp2[:] instead of jp2.read().
error ValueError: The 'crat' attribute is no longer available. ↓
cause Breaking change in version 0.14 removing old attributes.
fix
Use jp2.codestream.compression_ratios instead of jp2.codestream.crat.
Warnings
breaking Version 0.14 dropped support for Python 3.9 and 3.10. Requires Python >=3.11. ↓
fix Upgrade Python to 3.11 or later.
breaking In 0.14, the 'crat' and 'cdef' family of attributes were removed from Codestream. Use 'compression_ratios' and 'color_space' instead. ↓
fix Replace jp2.codestream.crat with jp2.codestream.compression_ratios and jp2.codestream.cdef with jp2.codestream.color_space.
gotcha glymur relies on OpenJPEG system library; missing or incompatible libopenjp2 can cause ImportError or silent failures. ↓
fix Install OpenJPEG via system package manager or conda (e.g., conda install -c conda-forge openjpeg).
gotcha Jp2k object indexing returns a view, not a copy; modifying the slice modifies the underlying data in place. ↓
fix Use .copy() if you need a separate array.
deprecated The glymur.Jp2k.read() method is deprecated in favor of direct indexing (jp2[:]) or waveform reading. ↓
fix Use jp2[:] to read full image data.
Imports
- glymur wrong
import Glymurcorrectimport glymur - Jp2k wrong
from glymur.Jp2k import Jp2kcorrectfrom glymur import Jp2k
Quickstart
import glymur
# Open a JPEG 2000 file
jp2 = glymur.Jp2k('input.jp2')
print('Shape:', jp2.shape)
print('Image data:', jp2[:])
# Write a JPEG 2000 file
import numpy as np
data = np.random.randint(0, 256, (256, 256), dtype=np.uint8)
glymur.Jp2k('output.jp2', data=data) # or use jp2.write(data)