在Python中保存1位深的二进制映像 [英] Save 1 bit deep binary image in Python

查看:156
本文介绍了在Python中保存1位深的二进制映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Python中有一个二进制映像,我想将其保存在我的PC中. 一旦存储在计算机中,我需要将其设置为1位深的png图像. 我怎样才能做到这一点?我尝试同时使用PIL和cv2,但无法将其保存为1位深度.

I have a binary image in Python and I want to save it in my pc. I need it to be a 1 bit deep png image once stored in my computer. How can I do that? I tried with both PIL and cv2 but I'm not able to save it with 1 bit depth.

推荐答案

使用:

cv2.imwrite(<image_name>, img, [cv2.IMWRITE_PNG_BILEVEL, 1])

(这仍将使用压缩,因此在实践中,每个像素很有可能少于1位)

(this will still use compression, so in practice it will most likely have less than 1 bit per pixel)

这篇关于在Python中保存1位深的二进制映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆