'Saving frames in opencv without compression

I'm trying to use the imwrite() OpenCV function. I want to save the frames with the .TIFF extension. The problem that I have is that the saved images are compressed so I can't use them. Any idea how I can escape this compression?

thanks in advance



Solution 1:[1]

Do not mind what sietschie says. The TIFF flag is hardcoded in the opencv binaries with a LZW compression. You can just turn this off (comment it out) or change it. In:

3rdparty/libtiff/tiff.h

Remove this line:

#define     COMPRESSION_LZW     5       /* Lempel-Ziv  & Welch */

Then compile. Presto. Tiff options other than that are automatically set (8 bit, 16bit, color, rgb, rgba,etc) depending on your image

Solution 2:[2]

The simplest way is recompiling OpenCV or direct using libtiff, but I consider as not very good idea changing 3rdparty/libtiff/tiff.h: after this modification you can't save compressed TIFFs at all with OpenCV, and under non-windows systems you usually have separate libtiff (not as a part of OpenCV).

I suggest simpler approach (still OpenCV recompilation, but you save possibility of writing compressed tiff and don't change libtiff directly): saving uncompressed TIFFs with OpenCV

Solution 3:[3]

cv::imwrite("imagen.TIFF", bayer, {cv::IMWRITE_TIFF_COMPRESSION, 1, 
cv::IMWRITE_TIFF_XDPI, 72,cv::IMWRITE_TIFF_YDPI,72}); 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TimZaman
Solution 2 Community
Solution 3 Pranav Choudhary