Search code examples
pythonopencvpython-imaging-librarycompressionimage-compression

Write a lossless-compressed image with multiple layers


How to save an image, losslessly compressed, with multiple layers (like with Photoshop PSD but rather an open format), with OpenCV cv2 or PIL/Pillow ?

Note: Is seems that TIFF format can do this (see this answer), but as I remember TIFF have lower compression ratio than PNG.

Pseudo code:

import cv2
cv2.imwrite('test.tiff', layer1, layer2, layer3)

Solution

  • The most comprehensive support for reading/writing TIFFs in Python is almost certainly tifffile.

    If you want lossless compression, try LZW and ZIP.