python - 无法使用 imageio reshape 数组。为什么?

标签 python python-imageio

我正在尝试使用 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/

相关文章:

python - Python中基于流的流量分析

python - 不同 Flask 实例中的 url_for

python - 如何使用模块 re 从数据帧的列中删除特殊字符?

python - ImportError : No module named flask. ext.mysql

python - 在python中获取类型错误

python - 每个 GPU 的 Nvenc session 限制

python - 水平组合几个 GIF - python

python - "float"读取帧时对象无法解释为整数

python - imageio在哪里找到 'chelsea.png'

arrays - 在Numpy Array中转换Python get request(jpg content)的响应