OpenCV Save a Mat as Binary (1-bit depth) TIFF

折月煮酒 提交于 2019-12-23 18:16:57

问题


Suppose we have a Mat after applying the OpenCv's Imgproc.adaptiveThreshold:

    Mat srcImage = ...;
    Mat binaryImage = new Mat();

    Imgproc.adaptiveThreshold(srcImage, binaryImage, 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,
        Imgproc.THRESH_BINARY, THRESHOLD_BLOCK_SIZE, 10);

When I save the binaryImage using Highgui.imwrite:

boolean isOk = Highgui.imwrite("sample.tiff", binaryImage);

Everything is ok except that output TIFF is not actually a binary TIFF - it's a 8-bit depth image:

What I'm trying to achieve is a similar to the below TIFF format with the 1-bit depth:

The question is how to do so with OpenCV?


回答1:


Only 8-bit (or 16-bit unsigned) single-channel or 3-channel images can be saved by imwrite.



来源:https://stackoverflow.com/questions/30889959/opencv-save-a-mat-as-binary-1-bit-depth-tiff

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