plt.imshow()仅显示黑白图像

时间:2020-09-22 10:28:26

标签: python matplotlib imshow

我正在尝试绘制显着图。原始图像(png文件形状为(224,224,3))是这样的:

original image

当我阅读图像并尝试使用plt.imshow(_img)对其进行绘制时,它看起来像这样:

enter image description here

因此,我的显着性地图如下所示:

enter image description here

我尝试将cmap用作rgbgray和其他功能。似乎没有任何效果。

有什么想法要解决吗?

编辑:

以下是我读取图像的代码:

_img = keras.preprocessing.image.load_img(img_,target_size=(512,512))
plt.imshow(_img)

print(type(_img)) print(_img.format) print(_img.mode) print(_img.size)

分别给出:

<class 'PIL.Image.Image'> None RGB (512, 512)

1 个答案:

答案 0 :(得分:0)

在显示图片之前尝试执行此操作:

tf.keras.preprocessing.image.img_to_array(_img,data_format = None,dtype = None)

相关问题