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

。_饼干妹妹 提交于 2020-06-26 07:19:17

问题



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!


回答1:


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.




回答2:


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);


来源:https://stackoverflow.com/questions/10205417/is-there-a-way-to-set-specific-compression-scheme-when-saving-tiff-file-in-openc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!