cookieMonster
cookieMonster

Reputation: 597

Is there a way to set specific compression scheme when saving tiff file in opencv?


I'm using opencv to crop tif files, everthing is fine, except for saving image to a file - opencv always uses LZW compression, but i don't need compression on resulting files, i do appreciate opencv's help in saving my disk drive space, but now is not the right time to do it.
So is there a way to save tif files with specific compression scheme (including no compression) or no?

Original images have no compression scheme applied and i'm using ROI to select area and SaveImage to save it to the target file. Any help appreciated!

Upvotes: 2

Views: 3078

Answers (2)

Jay Borseth
Jay Borseth

Reputation: 2003

In OpenCV 3 you can supply a vector of parameters to change things like compression or lines per strip, as in:

vector<int> params = { 
    259, 1,     // No compression, turn off default LZW
    279, 64     // Rows per strip 
};
imwrite("image.tiff", myImage, params);

Upvotes: 5

fireant
fireant

Reputation: 14538

The TIFF compression level is hard coded and cant be changed at run time. If you are compiling OpenCV on your machine, then you can edit the compression level in this file

3rdparty/libtiff/tiff.h

you will find this line:

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

Hope that helps.

Edit: see this line in the opencv code: https://github.com/Itseez/opencv/blob/b46719b0931b256ab68d5f833b8fadd83737ddd1/modules/imgcodecs/src/grfmt_tiff.cpp#L564 you should be able to pass the desired value for TIFFTAG_COMPRESSION, including COMPRESSION_NONE.

Upvotes: 3

Related Questions