2016-04-15 35 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') 
相關問題