C++ How can I down bit level with using 'resize'?? or is there Dithering function exist?

asked 2020-03-16 05:59:22 -0500

sehwan gravatar image

updated 2020-03-16 07:21:12 -0500

supra56 gravatar image

Hi. I wanna resize image without changing DPI and bit level. So I use this code.


vector<int> params2;
params2.push_back(XDPI);    // XDPI is same with original's
params2.push_back(YDPI);    // YDPI is same with original's

resize(ori_image, resized_image, Size(ori_image.cols , ori_image.rows));

imwrite("resized_test_image.tif", resized_image, params2);


I solved DPI problem with IMWRITE'_TIFF_XDPI But I dont know how to fix bit level. There is IMWRITE_PNG_BILEVEL in ImwriteFlags for Binary level PNG, 0 or 1, default is 0. But it cannot use for tiff image. Original image's bit level is 1 but resized image's bit level is 8. How can I fix bit level?? Or use other codes like dithering?

edit retag flag offensive close merge delete



without changing DPI

DPI is only used for printing, it does not play any role here, opencv will neither read nor write such info (it's all bogus)

Original image's bit level is 1 but resized image's bit level is 8

resize() does not change the bitlevel. conversion to 8bit probably happened while reading it in.

(there is no internal 1bit format for cv::Mat)

i somehow doubt, that opencv is the correct library for your problem

berak gravatar imageberak ( 2020-03-16 06:04:10 -0500 )edit