我正在处理一个与图像有关的问题,当我需要在网络训练之前检查图像绘制时,突然遇到了一些困难。我发现了一些奇怪的东西。我以为我的 ImageDataGenerator
没有正常工作,但实际上是 matplotlib
出了问题。我正在处理灰度图像。
如果您使用
data4 = np.random.randint(low=0,high=255,size=(137,236,4))
data3 = np.random.randint(low=0,high=255,size=(137,236,3))
data1 = np.random.randint(low=0,high=255,size=(137,236,1))
pyplot.imshow(data4)
pyplot.imshow(data3)
当你使用pyplot.imshow(data1)
时,它可以很好地绘制随机噪声,但是它会抛出一个错误:Invalid shape (137, 236, 1) for image data
。
但是同样的操作对于
data = np.random.randint(low=0,high=255,size=(137,236))
pyplot.imshow(data)
它的绘图非常好。为什么会发生这种情况?是什么导致在使用c=1时pyplot
出错?