Grok (JPEG2000 codec) plugin for Blosc2.
Project description
Blosc2 grok
A plugin of the excellent grok library for Blosc2. grok is a JPEG2000 codec, and with this plugin, you can use it as yet another codec in applications using Blosc2. See an example of use at: https://github.com/Blosc/blosc2_grok/blob/main/examples/params.py
Installation
For using blosc2_grok
you will first have to install its wheel:
pip install blosc2-grok -U
Usage
import blosc2
import numpy as np
import blosc2_grok
from PIL import Image
# Register the grok codec
blosc2.register_codec(blosc2_grok, 160)
# Set the params for the grok codec
kwargs = {}
kwargs['quality_mode'] = "dB"
kwargs['quality_layers'] = np.array([5], dtype=np.float64)
blosc2_grok.set_params_defaults(**kwargs)
# Define the compression and decompression parameters for Blosc2.
# Disable the filters and do not split blocks (these won't work with grok).
cparams = {
'codec': 160,
'filters': [],
'splitmode': blosc2.SplitMode.NEVER_SPLIT,
}
# Read the image
im = Image.open("examples/kodim23.png")
# Convert the image to a numpy array
np_array = np.asarray(im)
# Transform the numpy array to a blosc2 array. This is where compression happens, and
# the HTJ2K codec is called.
bl_array = blosc2.asarray(
np_array,
chunks=np_array.shape,
blocks=np_array.shape,
cparams=cparams,
urlpath="examples/kodim23.b2nd",
mode="w",
)
# Print information about the array, see the compression ratio (cratio)
print(bl_array.info)
Parameters for compression
The following parameters are available for compression for grok, with their defaults. Most of them are named after the ones in the Pillow library and have the same meaning. The ones that are not in Pillow are marked with a *
and you can get more information about them in the grok documentation, or by following the provided links.
'tile_size': (0, 0),
'tile_offset': (0, 0),
'quality_mode': None,
'quality_layers': np.zeros(0, dtype=np.float64),
'progression': "LRCP",
'num_resolutions': 6,
'codeblock_size': (64, 64),
'irreversible': False,
'precinct_size': (0, 0),
'offset': (0, 0),
'mct': 0,
* 'numgbits': 2, # Equivalent to -N, -guard_bits
* 'roi_compno': -1, # Together with 'roi_shift' it is equivalent to -R, -ROI
* 'roi_shift': 0,
* 'decod_format': GrkFileFmt.GRK_FMT_UNK,
* 'cod_format': GrkFileFmt.GRK_FMT_UNK,
* 'rsiz': GrkProfile.GRK_PROFILE_NONE, # Equivalent to -Z, -rsiz
* 'framerate': 0,
* 'apply_icc_': False, # Equivalent to -f, -apply_icc
* 'rateControlAlgorithm': GrkRateControl.BISECT,
* 'num_threads': 0,
* 'deviceId': 0, # Equivalent to -G, -device_id
* 'duration': 0, # Equivalent to -J, -duration
* 'repeats': 1, # Equivalent to -e, -repetitions
* 'verbose': False,
* 'enableTilePartGeneration': False, # See https://github.com/GrokImageCompression/grok/blob/a84ac2592e581405a976a00cf9e6f03cab7e2481/src/lib/core/grok.h#L975
* 'max_cs_size': 0, # See https://github.com/GrokImageCompression/grok/blob/a84ac2592e581405a976a00cf9e6f03cab7e2481/src/lib/core/grok.h#L975
* 'max_comp_size': 0, # See https://github.com/GrokImageCompression/grok/blob/a84ac2592e581405a976a00cf9e6f03cab7e2481/src/lib/core/grok.h#L975
More examples
See the examples directory for more examples.
That's all folks!
The Blosc Development Team
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 Distributions
Built Distributions
Hashes for blosc2_grok-0.1.0-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34c3c24822ded197c52b7b6a105512244380c389da93d51d06ebabc7d1a95fe3 |
|
MD5 | a0d597bc57cc511569e2267e75cbf729 |
|
BLAKE2b-256 | c85496a254b027c4df21147d11d82430a3ab1e5fe73a5f49e8eaa3e16813a380 |
Hashes for blosc2_grok-0.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecb74c392d448bf6007363f54b3260095864c6408806def258cc40a27e12d5bc |
|
MD5 | 8da4b6fad075cb5bab34ca42ea61c8ee |
|
BLAKE2b-256 | 8da1fad0fe6babfc05b9a8c641d102e11dea8946bfc04e11c31c647324a83b90 |
Hashes for blosc2_grok-0.1.0-py3-none-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd62d1332906e1cd50346304b9ffdacf126bda6d2a462f0e0206a55993ad93bc |
|
MD5 | 2241bafba64529f4d1727e94bf78085a |
|
BLAKE2b-256 | d1137f9646f9400e4969efa3a53b7d6e86dc7b772159df27946172c6ad77a805 |
Hashes for blosc2_grok-0.1.0-py3-none-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e97e07af73b9f63e437319f4803a8264a03310d7ac446dd0acc76115cc2c54e |
|
MD5 | f280559f72c8a2dca761e5b6d8a23fb0 |
|
BLAKE2b-256 | 9062267a920f12cb8d71aeca6153d7731ee64b6250e51a8af7c1bc90e177d7f2 |