【问题标题】:3d numpy array to grayscale picture3d numpy 数组到灰度图片
【发布时间】:2017-10-07 12:46:39
【问题描述】:

在提取 cifar10 数据集时,我遇到了维度为 32x32x3 的数组。

我可以用例如颜色绘制图像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,)

同时,我只是保存图像并再次读取它们,但我想有一种更优雅的方式可以直接将图片存储为灰度。

【问题讨论】:

标签: python arrays image numpy grayscale


【解决方案1】:

您可以使用您当前的 3D 数组使用 matplotlib 的 imshow 绘制灰度图像,如 here 所述。

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

【讨论】:

  • 我已经尝试过,各种 cmap/插值设置,它只是用彩色绘制;我真的不知道为什么: plt.imshow(train_data[2], cmap="gray") plt.show()
猜你喜欢
  • 2014-06-02
  • 1970-01-01
  • 2019-07-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-07
  • 2016-12-30
  • 1970-01-01
相关资源
最近更新 更多