{"id":24342,"library":"pyjpegls","title":"pyjpegls","description":"Python wrapper for the CharLS C++ library, providing JPEG-LS lossless and near-lossless image compression. Current version 1.5.1, requires Python >=3.9. Active development with occasional releases.","status":"active","version":"1.5.1","language":"python","source_language":"en","source_url":"https://github.com/planetlabs/pyjpegls","tags":["jpeg-ls","lossless","image-compression","charls","medical-imaging"],"install":[{"cmd":"pip install pyjpegls","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"Primary encoding function; also available as pyjpegls.encode","symbol":"encode","correct":"from pyjpegls import encode"},{"note":"Primary decoding function; also available as pyjpegls.decode","symbol":"decode","correct":"from pyjpegls import decode"},{"note":"Enum specifying allowed source array data types","symbol":"ImageFormat","correct":"from pyjpegls import ImageFormat"},{"note":"Common misspelling: 'Interleave' not 'Interleav'","wrong":"from pyjpegls import InterleavMode","symbol":"interleave_mode","correct":"from pyjpegls import InterleaveMode"},{"note":"Encapsulates encoding result metadata, including width/height/compute_lossless","wrong":"from pyjpegls.encoder import JpegLSEncoderInfo","symbol":"JpegLSEncoderInfo","correct":"from pyjpegls import JpegLSEncoderInfo"}],"quickstart":{"code":"import numpy as np\nfrom pyjpegls import encode, decode, ImageFormat, InterleaveMode\n\n# Create a sample 8-bit grayscale image (height, width)\nimage = np.random.randint(0, 256, size=(256, 256), dtype=np.uint8)\n\n# Encode (lossless by default)\nencoded = encode(image, interleave_mode=InterleaveMode.NONE)\nprint(f\"Encoded size: {len(encoded)} bytes\")\n\n# Decode back\ndecoded = decode(encoded)\nprint(f\"Decoded shape: {decoded.shape}, dtype: {decoded.dtype}\")\n\n# Verify lossless reconstruction\nassert np.array_equal(image, decoded), \"Lossless check failed\"","lang":"python","description":"Encode and decode a grayscale image with default lossless settings."},"warnings":[{"fix":"Ensure your numpy array shape is (height, width, channels) for color or (height, width) for grayscale.","message":"The library expects numpy arrays in (height, width) order, not (width, height). Misordered dimensions can cause silent incorrect encoding or runtime errors.","severity":"gotcha","affected_versions":"all"},{"fix":"Cast your array to one of the supported types before encoding: image.astype(np.uint8) or np.int16 or np.uint16.","message":"Supported input dtypes are uint8, int16, and uint16 only (including signed/unsigned). Using other dtypes (e.g., float32) will raise a ValueError.","severity":"gotcha","affected_versions":"all"},{"fix":"For RGB images: ensure shape is (H, W, 3) and use InterleaveMode.SAMPLE.","message":"For color (multi-plane) images, the array should be in (height, width, planes) order and must use InterleaveMode.SAMPLE (pixel interleaved) or InterleaveMode.LINE (line interleaved). InterleaveMode.NONE is for single-plane grayscale only.","severity":"gotcha","affected_versions":"all"},{"fix":"Use Image.fromarray(decoded) if you need a PIL Image (after appropriate mode/format conversion).","message":"The decode function returns a numpy array; it does not return a PIL Image or any other object. Converting to PIL requires explicit conversion.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Set interleave_mode=InterleaveMode.SAMPLE for pixel-interleaved color images (shape H,W,3).","cause":"Using InterleaveMode.NONE for a color (multi-plane) image.","error":"ValueError: Invalid interleave mode for given image dimensions"},{"fix":"Cast image to supported dtype: image = image.astype(np.uint8) or np.int16, np.uint16.","cause":"Input array dtype is not one of uint8, int16, uint16.","error":"ValueError: Unsupported data type: float32"},{"fix":"Install pyjpegls >=1.0 and use: from pyjpegls import encode. For older versions use: from pyjpegls._core import encode.","cause":"Outdated pyjpegls version (<1.0) or import from wrong module. The encode/decode functions are top-level since v1.0.","error":"AttributeError: module 'pyjpegls' has no attribute 'encode'"},{"fix":"Use interleave_mode=InterleaveMode.NONE for grayscale (2D) images.","cause":"Attempting to encode a 2D array with InterleaveMode.SAMPLE (which expects 3D).","error":"ValueError: can only convert an array of size 1 to a Python scalar"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}