跳转到主要内容

Blosc2的Grok (JPEG2000编解码器) 插件。

项目描述

Blosc2 grok

优秀的grok库的Blosc2插件。grok是JPEG2000编解码器,使用此插件,您可以将其用作Blosc2应用程序中的另一个编解码器。查看使用示例: https://github.com/Blosc/blosc2_grok/blob/main/examples/params.py

安装

要使用blosc2_grok,您首先必须安装其wheel

pip install blosc2-grok -U

用法

import blosc2
import numpy as np
import blosc2_grok
from PIL import Image

# Set the params for the grok codec
kwargs = {}
kwargs['cod_format'] = blosc2_grok.GrkFileFmt.GRK_FMT_JP2
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': blosc2.Codec.GROK,
    '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)

压缩参数

以下参数可用于grok的压缩,默认值如下。其中大部分与Pillow库中的参数同名,含义相同。不在Pillow中的参数用*标记,您可以在grok文档中或通过提供的链接获取更多信息。对于标记为**的,您可以在grok.h头文件中获取更多信息。

'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
* 'mode': GrkMode.DEFAULT,  # Equivalent to -M, -mode
* 'verbose': False,  # Equivalent to -v, -verbose
** 'enableTilePartGeneration': False,  # See header of grok.h above
** 'max_cs_size': 0,  # See header of grok.h above
** 'max_comp_size': 0,  # See header of grok.h above

codec_meta作为比率、质量、模式

作为一种更简单的激活码率质量模式的方法,如果您将 cparams 中的 codec_meta 设置为非0的整数,则码率质量模式将以 codec_meta / 10 的码率值被激活。如果未指定 cod_format,则将使用默认值。在此情况下,codec_meta 参数优先于通过 blosc2_grok.set_params_defaults() 设置的 rates 参数。

import blosc2


cparams = {
    'codec': blosc2.Codec.GROK,
    'codec_meta': 5 * 10,  # cratio will be 5
    'filters': [],
    'splitmode': blosc2.SplitMode.NEVER_SPLIT,
}

更多示例

有关更多示例,请参阅 示例目录

感谢

感谢 Marta Iborra,来自 Blosc 开发团队,为使此插件成为可能所做的大部分工作,以及 J. David Ibáñez 和 Francesc Alted 对初始贡献。还要感谢 Aaron Boxer,grok 库 的原始作者,在解决使这种交互成为可能的问题方面提供的帮助。

这就完了!

Blosc 开发团队

项目详情


下载文件

下载适合您平台文件的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源代码分发

此版本没有可用的源代码分发文件。请参阅 生成分发存档 的教程。

构建分发

blosc2_grok-0.3.3-py3-none-win_amd64.whl (4.0 MB 查看散列值)

上传时间 Python 3 Windows x86-64

blosc2_grok-0.3.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB 查看散列值)

上传时间 Python 3 manylinux: glibc 2.17+ x86-64

blosc2_grok-0.3.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.2 MB 查看散列值)

上传时间 Python 3 manylinux: glibc 2.17+ ARM64

blosc2_grok-0.3.3-py3-none-macosx_11_0_arm64.whl (1.6 MB 查看散列值)

上传时间 Python 3 macOS 11.0+ ARM64

blosc2_grok-0.3.3-py3-none-macosx_10_9_x86_64.whl (1.9 MB 查看散列值)

上传时间 Python 3 macOS 10.9+ x86-64

由以下支持