2016-04-15 110 views
1

原始MNIST图像是带有灰度字符的白色背景。 0代表白色,255代表黑色,中间是灰色阴影。我正在使用由keras提供的使用相同格式的数据集的副本。与matplotlib imshow()一起使用哪个cmap(colormap)将MNIST数据集图像显示为白色背景上的黑色字符

只是为了看看事情,我使用matplotlib来显示数据集的示例,但是当我选择'gray'的cmap时,我会得到黑色背景,下面是白色字符。

import matplotlib.pyplot as plt 
    plt.imshow(X_train[0], cmap='gray') 

enter image description here

有没有将正确地在白色背景上显示的图像以黑颜色表的另一个?

回答

4

您可以使用invert the colormap(使用颜色映射的*_r版本)或反转(否定)数据。

# Invert the colormap 
plt.imshow(X_train[0], cmap='gray_r') 

# Invert your data 
plt.imshow(-X_train[0], cmap='gray') 
相关问题