python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
12.24k stars 2.23k forks source link

Support for partial decoding of JPEG 2000 and pyramid TIFs #4111

Open marma opened 5 years ago

marma commented 5 years ago

Hi!

I'm using PIL to serve images using the IIIF protocol and have a performance question. Has there been any work done, or interest shown, in partial decoding of JPEG2000-images (and multi-resolution TIFs)?

There are two things that speed up the decompression of an image a lot when using opj_decompress: (1) reducing the size and quality layers and (2) cropping.

This is useful when creating tiles and/or thumbnails on the fly from large image collections, i.e when you don't want to create and save a huge number of pre-scaled/cropped tiles and sizes. As far as I can tell you can set Jpeg2KImageFile.reduce and .layers to decrease the final size which will result in faster decode time, but there is no way to decode only the cropped region. Am I correct, or is there any way to tell PIL to tell OpenJPEG to do partial decoding?

Best regards, Martin

radarhere commented 1 day ago

Regarding multi-resolution / pyramid TIFFs, while https://github.com/python-pillow/Pillow/issues/3053 indicates we have some support, this may relate to #1888 - see https://github.com/python-pillow/Pillow/issues/1888#issuecomment-2112706708

I'd still recommend using gdal backed (e.g. rasterio) readers/writers for that, as we've got 0 support for pyramids, spatial metadata, and tiled tiffs. It's a huge field, and we're not even at square 1 for it.

So I'm not convinced that we have good support for that type of data, even before talking about partial decoding. An example file might help narrow the focus of this question.