PIL:PNG用4个通道读取,但它是黑色和白色

时间:2017-07-20 21:12:25

标签: python image python-imaging-library channels

我正在使用PIL打开图像,但其形状被读取为(400,256,4),而应该是(400,256,1)。这是我的代码:

from PIL import Image
img = Image.open(file_name)
img = np.array(img)
print(img.shape) # (400, 256, 4)

这与我制作图像时的编码方式有关,还是有办法以1波段的形式读取图像?

为了参考图像,我使用matplotlib的https://matplotlib.org/devdocs/api/_as_gen/matplotlib.pyplot.savefig.html

对其进行编码

0 个答案:

没有答案
相关问题