问题描述
我正在尝试使用PIL打开图像(.png
)。但是,它仅显示两种颜色的图像。
原始图片(即3.24 MB)。我减小了大小,因为系统仅允许我们上传2MB以下的文件:
当我运行image = Image.open('path/image')
时,它显示以下内容:
当我运行相同命令但进行转换时,image = Image.open('path/image').convert('L')
我明白了:
这是我绘制图像的方式:
fig,ax = plt.subplots()
ax.imshow(image)
ax.grid(False)
我尝试了数十幅图像。没变化。我强烈猜测由图像通道引起的问题。函数以某种方式将3通道读取为单通道或以其他方式读取。任何想法如何解决???
编辑:这样我就接近了想要的结果。我首先将iamge转换为数组。但这还不够。
代码如下:
image = Image.open(df['Path'][0])
image = np.asarray(image)
plt.imshow(image)