我正在尝试使用 imageio
模仿这行代码的作用:
img_array = scipy.misc.imread('/Users/user/Desktop/IMG_5.png', flatten=True)
img_data = 255.0 - img_array.reshape(784)`
但是当使用 imageio
我得到:
img = imageio.imread('/Users/user/Desktop/IMG_5.png')
img.flatten()
输出:图像([212, 211, 209, ..., 192, 190, 191], dtype=uint8)
img.reshape(1, 784)
ValueError: cannot reshape array of size 2352 into shape (1,784)
谁能解释一下这是怎么回事,为什么我的图片大小是 2352?在导入之前,我将图像调整为 28x28 像素。
最佳答案
我知道这个问题已经有了一个可接受的答案,但是,它意味着使用 skimage
库而不是 imageio
作为问题(和 scipy
) 建议。就这样吧。
根据 imageio's doc on translating from scipy,您应该将 flatten
参数更改为 as_gray
参数。
所以这一行:
img_array = scipy.misc.imread('/Users/user/Desktop/IMG_5.png', flatten=True)
应该给你同样的结果:
img_array = imageio.imread('/Users/user/Desktop/IMG_5.png', as_gray=True)
它对我有用。如果它对您不起作用,则可能还有另一个问题。提供图片作为示例可能会有所帮助。
关于python - 无法使用 imageio reshape 数组。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47822318/