cgohlke / imagecodecs

Image transformation, compression, and decompression codecs
https://pypi.org/project/imagecodecs
BSD 3-Clause "New" or "Revised" License
119 stars 23 forks source link

More options for zlib encoder #117

Closed hmaarrfk closed 1 week ago

hmaarrfk commented 1 week ago

On the back of https://github.com/cgohlke/tifffile/issues/273 I'm requesting your thoughts on adding more options to the zlib compressor.

The PNG format seems to be very efficient at compressing even "natural" microscopy images. However, shoving it in a TIFF tag make it "unreadable" by default by many image viewers that don't expect it. I'm hoping we can provide enough options for users to recreate the effect of PNG with TIFF and ZLIB with the appropriate options.

Mainly, libpng by default seems to use the "filtered" strategy. However, this isn't accessible unless you use the deflateInit2 to instantiate a zlib stream object pointer.

It might require a bit of massing but I'm wondering if you are open to such contributions.

let me know.

hmaarrfk commented 1 week ago

Just not to self. this might be of limited use since beyond the zlib filters, it seems that png uses an additional pre-filtering step that helps with the encoding process.

cgohlke commented 1 week ago

TIFF has it's own simple pre-filters, called predictors. PNG is only used in ZIFF.

There are already three "zlib" codecs in imagecodecs. I think libdeflate is a good default for TIFF. It is also used by libtiff if enabled at build time. I rather add an option to pass an encoder callback function with tifffile's compressionargs argument such that any compatible codec (for example, zlib-ng or isa-l) can be used for experimentation.

hmaarrfk commented 1 week ago

TIFF has it's own simple pre-filters, called predictors. PNG is only used in ZIFF.

Wow. Magic. Thank you so much for this pointer. Every time I open an issue here I feel like I learn something really new and cool! Horizontal predictor + zlibng works really well...

I'll close this and continue the discussion on tifffile's feedstock since you seem to prefer to add options there for customization.