2017-10-07 139 views
0

同時提取cifar10數據集im面對32x32x3維度的數組。3d numpy數組灰度圖片

我可以用例如顏色繪製圖像的顏色。 plt.imshow(train_data [2]);用灰度值將數組轉換爲32x32維的常用方法是什麼?

train_data, train_labels, test_data, test_labels = 
load_cifar10_data(data_dir) 

print(train_data.shape) 
print(train_labels.shape) 

輸出:

(50000,32,32,3) (50000)

同時,我只是保存圖像,然後再次讀取他們,但我想有以更加優雅的方式直接將圖片存儲爲灰度。

+0

的可能重複[我怎樣才能將RGB圖像轉換爲灰度在Python?](https://stackoverflow.com/questions/12201577/how-can-i-convert-an-rgb-image- python) – DJK

回答

0

您可以使用您當前的3D陣列使用matplotlib的imshow繪製灰度圖像,如here所述。

import matplotlib.pyplot as plt 
plt.imshow(train_data , cmap = "gray") 
+0

我已經試過了,各種cmap /插值設置,它只是繪製顏色;我真的不知道爲什麼:plt.imshow(train_data [2],cmap =「gray」) plt.show() –