{"library":"pylibjpeg-openjpeg","title":"pylibjpeg-openjpeg","description":"pylibjpeg-openjpeg is a Python wrapper for the OpenJPEG library, specifically designed as a plugin for pylibjpeg. It enables JPEG 2000 (J2K) decoding and encoding for various image data, including DICOM pixel data. The current version is 2.5.0, and releases often coincide with new Python versions or updates to the underlying OpenJPEG library, typically every few months.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install pylibjpeg-openjpeg"],"cli":null},"imports":["from pylibjpeg_openjpeg import openjpeg","from pylibjpeg import register_plugin\nregister_plugin('openjpeg', 'pylibjpeg_openjpeg')"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import numpy as np\nfrom pylibjpeg_openjpeg import openjpeg\n\n# Example: Encoding a simple NumPy array to JPEG 2000\n# For real use, ensure data matches expected type/shape for J2K\nwidth, height = 128, 128\narray_data = np.arange(width * height, dtype=np.uint16).reshape((height, width))\n\n# Encode to JPEG 2000 (lossless example)\nencoded_data = openjpeg.encode_pixel_data(\n    array_data,\n    bits_allocated=16,\n    bits_stored=16,\n    high_bit=15,\n    photometric_interpretation='MONOCHROME2',\n    samples_per_pixel=1,\n    rows=height,\n    columns=width,\n    j2k_codec='jp2',\n    lossless=True\n)\n\nprint(f\"Encoded data length: {len(encoded_data)} bytes\")\n\n# Decode the data back\ndecoded_array, image_format = openjpeg.decode_pixel_data(\n    encoded_data,\n    rows=height,\n    columns=width,\n    bits_allocated=16,\n    bits_stored=16,\n    high_bit=15,\n    photometric_interpretation='MONOCHROME2',\n    samples_per_pixel=1\n)\n\nprint(f\"Decoded array shape: {decoded_array.shape}, dtype: {decoded_array.dtype}\")\nassert np.array_equal(array_data, decoded_array)\nprint(\"Original and decoded arrays are equal (lossless encoding verified).\")\n","lang":"python","description":"This quickstart demonstrates direct usage of pylibjpeg-openjpeg's `encode_pixel_data` and `decode_pixel_data` functions using NumPy arrays. For DICOM integration, you typically register the plugin with `pylibjpeg` and then use `pylibjpeg.decode()`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}