好的,我刚开始使用python,我需要将一个图像转换为4bpp作为工具,我遇到了pypng,但我找不到如何仅转换为4的深度,所以这是我通过查看几十个示例得出的结果:
import png
import numpy as np
with open("temporarypng.png", 'wb') as f:
w_depth = png.Writer(im.shape[1], im.shape[0], bitdepth=16)
im_uint16 = np.round(im).astype(np.uint16)
w_depth.write(f, np.reshape(im_uint16, (-1, im.shape[1])))
f.close()
毫不奇怪,它不起作用。有人能帮我吗
如果您需要
4bpp
,那么您应该使用bitdepth=4
,并且您必须使用值0..15
(对于灰度图像)创建array
,对于palette
(对于彩色图像)创建16个值(R,G,B)
的数组我使用
PIL
加载RGB
图像,并将其转换为具有16种颜色的图像/索引到具有16种颜色的调色板(RGB
)输入
RGB
图像用调色板输出
4bpp
不带调色板的输出
4bpp
相关问题 更多 >
编程相关推荐