简体   繁体   English

3D Numpy数组到灰度图片

[英]3d numpy array to grayscale picture

while extracting the cifar10 dataset im confronted by arrays with the dimension of 32x32x3. 同时提取尺寸为32x32x3的数组面对的cifar10数据集im。

i can plot the image in colour with eg plt.imshow(train_data[2]); 我可以用例如plt.imshow(train_data [2])绘制彩色图像。 whats a common way to transform the array to the dimension 32x32 with grayscale values? 用灰度值将数组转换为尺寸为32x32的常用方法是什么?

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

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

output: 输出:

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

meanwhile, i'm just saving the images and read them again, but i guess there is a by far more elegant way to directly store the pictures to grayscale. 同时,我只是保存图像并再次读取它们,但是我想有一种更加优雅的方法将图片直接存储为灰度。

You can use your current 3D array to plot a grayscale image using matplotlib's imshow as described here . 您可以使用目前的3D阵列使用matplotlib的绘制灰度图像imshow描述这里

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM