【问题标题】:How can I assign pixel values of an image to an array in Python如何将图像的像素值分配给 Python 中的数组
【发布时间】:2019-07-16 07:14:09
【问题描述】:

我想导入一个图像并将所有像素值存储在一个数组中。我该怎么做?

这是我已经尝试过的,但是数组是错误的。

from PIL import Image
im = Image.open('red-flower.jpg', 'r')
pix_val = list(im.getdata())

【问题讨论】:

  • 使用numpy.array(im.getdata())?
  • 我的回答解决了你的问题吗?如果是这样,请考虑接受它作为您的答案 - 通过单击计票旁边的空心对勾/复选标记。如果没有,请说出什么不起作用,以便我或其他人可以进一步为您提供帮助。谢谢。 meta.stackexchange.com/questions/5234/…

标签: python arrays numpy scipy


【解决方案1】:

Image.open() 的参数错误:

import numpy as np
from PIL import Image

im = Image.open('red-flower.jpg')
array = np.array(im)

文档here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多