【问题标题】:Which cmap (colormap) to use with matplotlib imshow() to diplay the MNIST dataset images as black characters on white background哪个 cmap (colormap) 与 matplotlib imshow() 一起使用以将 MNIST 数据集图像显示为白色背景上的黑色字符
【发布时间】:2016-04-15 15:54:04
【问题描述】:

原始的 MNIST 图像是白色背景,上面有灰度字符。 0 代表白色,255 代表黑色,中间是灰色阴影。我正在使用keras 提供的数据集副本,它使用相同的格式。

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

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

是否有另一种颜色图可以正确地将图像显示为白色背景上的黑色?

【问题讨论】:

    标签: python matplotlib colormap mnist


    【解决方案1】:

    您可以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')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-13
      • 2018-05-16
      • 2014-04-21
      • 2022-09-24
      • 1970-01-01
      相关资源
      最近更新 更多