Skip to main content

Blosc2 OpenHTJ2K

This is a dynamic codec plugin for Blosc2 that allows to compress and decompress images using the High Throughput JPEG 2000 standard. The HT version brings increased performance when compared to the traditional JPEG 2000. For details, check the HTJ2K whitepaper.

To provide this feature this plugin uses the OpenHTJ2K library.

Install

The Blosc2 OpenHTJ2K plugin is distributed as a Python wheel:

pip install blosc2-openhtj2k

There are wheels for Linux, macOS and Windows. As of now, only the x86-64 architecture is supported.

Usage from Python

The examples are not distributed with the wheel, but you can just clone the project:

git clone https://github.com/Blosc/blosc2_openhtj2k.git
cd blosc2_openhtj2k

In the examples folder there are the compress and decompress scripts, both take two required arguments, for the input and output file:

  • compress.py takes as first argument the path to an image, and the second argument the path to the output file, which should end by the .b2nd extension.

  • decompress.py takes as first argument the path to the Blosc2 file generated by compress.py, and second argument the path to the output image.

To try out these scripts first install the required software:

pip install blosc2-openhtj2k
pip install Pillow

Then you can run the scripts, from the examples folder, for example:

cd examples
python compress.py kodim23.png /tmp/kodim23.b2nd
python decompress.py /tmp/kodim23.b2nd /tmp/kodim23.png

Note that the examples cannot be run from the project's root, because it will fail to import blosc2_openhtj2k, since there's a directory with that name.

For details on the arguments these commands accept call them with the --help option.

Below follows more detailed docs on how to accomplish the compression and decompression.

Compression

Load the image

To compress an image first we need to load it, and to transform it to a Numpy array, then Blosc2 will compress that array.

For loading the image, and getting the Numpy array, we are going to use the Pillow library:

from PIL import Image
im = Image.open(args.inputfile)
np_array = np.asarray(im)

Transform the Numpy array

Before feeding this array to Blosc2, we need to massage it a bit, because its structure is different from what is expected by the OpenHTJ2K plugin. As can be seen in the compress.py script, these are the transformations required, with comments:

# Transpose the array so the channel (color) comes first
# Change from (height, width, channel) to (channel, width, height)
np_array = np.transpose(np_array, (2, 1, 0))

# Make the array C-contiguous
np_array = np_array.copy()

# The library expects 4 bytes per color (xx 00 00 00), so change the type
np_array = np_array.astype('uint32')

Plugin options

It's possible to configure the OpenHTJ2K plugin with a number of options, this step is optional. For example:

import blosc2_openhtj2k
blosc2_openhtj2k.set_params_defaults(
    transformation=0,   # 0:lossy 1:lossless (default is 1)
)

Once the options above are set, these remain for all future calls, until they are changed again.

Blosc2 parameters

Note that:

  • We must tell Blosc2 to use the OpenHTJ2K codec, passing its corresponding id BLOSC_CODEC_OPENHTJ2K.

  • At this time the plugin does not support multithreading, so the number of threads must be explicitly defined to 1.

  • OpenHTJ2K expects to work with images, so this plugin won't work well when combined with regular Blosc2 filters (SHUFFLE, BITSHUFFLE, BYTEDELTA...), nor with split mode, because they change the image completely; so these must be reset.

With that, we typically define the compression and decompression parameters like this:

nthreads = 1
cparams = {
    'codec': blosc2.Codec.OPENHTJ2K,
    'nthreads': nthreads,
    'filters': [],
    'splitmode': blosc2.SplitMode.NEVER_SPLIT,
}
dparams = {'nthreads': nthreads}

Actual OpenHTJ2K compression

Now we can call the command that will compress the image using Blosc2 and the OpenHTJ2K plugin:

bl_array = blosc2.asarray(
    np_array,
    chunks=np_array.shape,
    blocks=np_array.shape,
    cparams=cparams,
    dparams=dparams,
)

Note that:

  • We set the chunk and block shape to match the image size, as this is well tested.

  • If you pass the urlpath the Blosc2 array will be saved to the given path, for example `urlpath=/tmp/image.b2nd'.

Decompression

If the Blosc2 array was saved to a file with a different program, we will need to read it first:

array = blosc2.open(args.inputfile)

Now decompressing it is easy, we will get a Numpy array:

np_array = array[:]

But prior to obtain the image, we must undo the transformations done when compressing:

# Get back 1 byte per color, change dtype from uint32 to uint8
np_array = np_array.astype('uint8')

# Get back the original shape: height, width, channel
np_array = np.transpose(np_array, (2, 1, 0))

Now we can get the Pillow image from the Numpy array:

im = Image.fromarray(np_array)

Which can be saved or displayed:

im.save(...)
im.show()

Metadata

Release files for blosc2-openhtj2k 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for blosc2-openhtj2k 0.1.2
File
blosc2_openhtj2k-0.1.2-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
blosc2_openhtj2k-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
blosc2_openhtj2k-0.1.2-cp311-cp311-macosx_10_9_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.9+ x86-64 Details
blosc2_openhtj2k-0.1.2-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
blosc2_openhtj2k-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
blosc2_openhtj2k-0.1.2-cp310-cp310-macosx_10_9_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.9+ x86-64 Details
blosc2_openhtj2k-0.1.2-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
blosc2_openhtj2k-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
blosc2_openhtj2k-0.1.2-cp39-cp39-macosx_10_9_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.9+ x86-64 Details
blosc2_openhtj2k-0.1.2-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
blosc2_openhtj2k-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details
blosc2_openhtj2k-0.1.2-cp38-cp38-macosx_10_9_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.9+ x86-64 Details

Total release size: 6.2 MB

Release files / blosc2_openhtj2k-0.1.2-cp311-cp311-win_amd64.whl

Download URL blosc2_openhtj2k-0.1.2-cp311-cp311-win_amd64.whl
Size 160.3 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
c00adf23b6c21f01925f0d067ccf13666a651eeced9ba2af47cb28f2f903869f
BLAKE2b-256 checksum
How to use checksums
37118994b719bedad791297681f4b5ed7c2a1b0daea11809ad9fd260a2bb721b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / blosc2_openhtj2k-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL blosc2_openhtj2k-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 358.8 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
d5a5271258518cb3b4ca4371a5ac2631c1114cefe02536f5adb41b4b72f365c6
BLAKE2b-256 checksum
How to use checksums
cd32f0f60b86aa01bd8543dd0ac00ae271090433b46bd09281b9d3d3a44deed0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / blosc2_openhtj2k-0.1.2-cp311-cp311-macosx_10_9_x86_64.whl

Download URL blosc2_openhtj2k-0.1.2-cp311-cp311-macosx_10_9_x86_64.whl
Size 1.0 MB
Tags CPython 3.11 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
46f1f8a01a2d85e07ef658a183a80f42308004f40630c21a5941c68cc7af03c3
BLAKE2b-256 checksum
How to use checksums
d6d155d63043753ca350c9e9ec5cd7ec231ea6d07a8bb46446334ef366835749
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / blosc2_openhtj2k-0.1.2-cp310-cp310-win_amd64.whl

Download URL blosc2_openhtj2k-0.1.2-cp310-cp310-win_amd64.whl
Size 160.3 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
5e7ce77e8766f363884713b50d829d55517c75332cb9d1c9b17edc92f88d7e75
BLAKE2b-256 checksum
How to use checksums
d6564790bc1b58de1b3ba5c0120953cf98b893a6f388e87e82b76dac0bcd1603
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / blosc2_openhtj2k-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL blosc2_openhtj2k-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 358.8 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
d61a403e3dc114a9378366664003adfe9cb867ce451ad2a8d3dd0540d7b41fe9
BLAKE2b-256 checksum
How to use checksums
eadf2f59c31700292f4d7d3c5a8825ccd648937cf1081d9233ebdb694e8a09bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / blosc2_openhtj2k-0.1.2-cp310-cp310-macosx_10_9_x86_64.whl

Download URL blosc2_openhtj2k-0.1.2-cp310-cp310-macosx_10_9_x86_64.whl
Size 1.0 MB
Tags CPython 3.10 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
f3e47a0349b2ab566dc74dbe930d2c9cdad1def29cbdff27faa61b9aedfe69c3
BLAKE2b-256 checksum
How to use checksums
c8d2095fa01285d3411d075ae337119ee5e74eb5a398b406a3f1cbf63799e9c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / blosc2_openhtj2k-0.1.2-cp39-cp39-win_amd64.whl

Download URL blosc2_openhtj2k-0.1.2-cp39-cp39-win_amd64.whl
Size 160.3 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
237321c0d49e10d644698446d110ae28b5ca97c50bd873f277ee27354e82f72b
BLAKE2b-256 checksum
How to use checksums
099b6f13e861db21f4336495055592b9cb52a6099faf04e22f8cba27a05b6afb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / blosc2_openhtj2k-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL blosc2_openhtj2k-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 358.8 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
900a6e5617a0100db8885f492ecc17b0e3130c0e02120f63066c274a8f441448
BLAKE2b-256 checksum
How to use checksums
bd293f5b02463003059afa304a6d3a3cb5bf443e8f3c64fa3ed9b74eba58cf9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / blosc2_openhtj2k-0.1.2-cp39-cp39-macosx_10_9_x86_64.whl

Download URL blosc2_openhtj2k-0.1.2-cp39-cp39-macosx_10_9_x86_64.whl
Size 1.0 MB
Tags CPython 3.9 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
8ba21a577ca83a84f74840346b82582b42f5558aea08428bc2f71c7c8aa1c22d
BLAKE2b-256 checksum
How to use checksums
bae23888cd0b28111e52b3f83073862c9aa8c8244b12ac80d41986ea821338da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / blosc2_openhtj2k-0.1.2-cp38-cp38-win_amd64.whl

Download URL blosc2_openhtj2k-0.1.2-cp38-cp38-win_amd64.whl
Size 160.3 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
dd16ab1c474b192b2aab36556ff7ddf4c57a6e9bea948262699bdb260894187d
BLAKE2b-256 checksum
How to use checksums
e8eadc85a2f6041eaebcc9a72cdad27fec8742ff04cceea179ceca178e0ded15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / blosc2_openhtj2k-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL blosc2_openhtj2k-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 358.8 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
92bdce204c3fa37da8c2011cb3a6cc729c3bd9a66ab9adb2b2ad90fe1b177e6b
BLAKE2b-256 checksum
How to use checksums
99d13b68260100ea96d6bf53e15765b773507bd7ffa349f39c19fbdfb255e2d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / blosc2_openhtj2k-0.1.2-cp38-cp38-macosx_10_9_x86_64.whl

Download URL blosc2_openhtj2k-0.1.2-cp38-cp38-macosx_10_9_x86_64.whl
Size 1.0 MB
Tags CPython 3.8 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
e335a5c20cb7a945f681cf89bb65515280b10809498b1b8ab99abeacf4041fd4
BLAKE2b-256 checksum
How to use checksums
bab34fdced4b90e414b9ffd9854ee02f282ef55225a215f89acf80b684c9ba43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release history Release notifications | RSS feed

This release

0.1.2 This release

12 release files

0.1.0

12 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page