%matplotlib inline
from keras.preprocessing import image
import matplotlib.pyplot as plt
import numpy as np
img = np.random.rand(224,224,3)
plt.imshow(img)
plt.show()
img_path = "image.jpeg"
img = image.load_img(img_path, target_size=(224, 224))
print(type(img))
x = image.img_to_array(img)
print(type(x))
print(x.shape)
plt.imshow(x)
我有一些这样的代码可以打印图像。但它在错误的 channel 中显示图像。我在这里缺少什么?
最佳答案
这是图像缩放问题。 imshow() 的输入期望它在 0-1 范围内,而您向它传递 [0-255] 范围输入。尝试将其视为:
plt.imshow(x/255.)
关于python - 如何加载图像并使用keras显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44841869/