We received 50 TB of 16-bit uncompressed TIF images from an industrial sensor on our server, and we want to compress them with lossless zip compression using python. Using python because it’s easier to use Python to link our database.
However, after several hours of searching and reading the documentation, I found that there was not even a ripe python library that can convert a 16-bit TIF to a compressed zip tif file. The last PIL cannot write compressed tif, a file with OpenCV hard code in LZW tif, not zip (deflate). And there is not enough documentation in smc.freeimage, PythonImageMagick, so I don't know if they can do this. I also found this tifffile.py , something like compression in its source code, but there is no example code that allows me to understand how to configure the compression option for output.
Of course, I can use an external executable, but I just don't want to use python as a scripting language.
So I really appreciate if someone gives me an effective example, thanks.
Update:
cgohlke code works, here I provide another lightweight solution. Check out the correct pythontifflib code here https://github.com/delmic/pylibtiff .
The original PythonTiffLib from Google code does not handle RGB information very well and it doesn’t work with my data, this fixed version works, however, since the code is very old, it means that PythonTiffLib may not be supported very well.
Use the following code:
from libtiff import TIFF tif = TIFF.open('Image.tiff', mode='r') image = tif.read_image() tifw = TIFF.open('testpylibtiff.tiff', mode='w') tifw.write_image(image, compression='deflate', write_rgb=True)