【发布时间】:2021-10-06 13:06:58
【问题描述】:
我正在尝试使用 python PIL 读取 RGBA BMP,但它似乎不起作用。 以下代码段显示 tensorflow bmp_decode 函数成功完成此任务,而 PIL 没有:
def read_image_tf(filename):
image_file = tf.read_file(filename, name='read_file')
decoded_bmp = tf.io.decode_bmp(bmp_image)
return decoded_bmp
def read_img_pil(filename):
img = np.asarray(Image.open(fh))
return img
img = K.eval(read_image_tf(<FILENAME>))
print (img.shape)
img = read_img_pil(<FILENAME>)
print (img.shape)
输出:
(3892, 3892, 4)
(3892, 3892, 3)
当尝试在 Image.open(fh) 上运行 imgobj.convert('RGBA') 时,我只是得到一个仅包含 255 值的矩阵(100% 透明度,这不是每个像素的正确 alpha 值)。
PIL 中是否存在错误?有没有使用 python 读取 RGBA 的替代方法?
【问题讨论】:
-
可以分享一下麻烦的BMP文件吗?您可能必须使用 Dropbox 或 Google Drive 或类似工具。
标签: python python-imaging-library