【发布时间】:2020-01-03 11:27:39
【问题描述】:
使用 opencv 读取图像很简单:
import cv2
im = cv2.imread("image.png")
print(im)
输出一个 numpy 数组,其中数组项表示图像像素值,范围从 0 到 255。
有没有办法使用 Python 标准库提取相同的像素值?预期的输出将采用 Python 内置数据结构的形式(即列表/元组/等)。例如:
[[191, 123, 100, 255],
[233, 101, 120, 255]
...
]
到目前为止,我所拥有的是:
file = open("small.png", 'rb')
content= file.read()
print(content)
这将产生一个字节对象,但我如何获得图像的实际像素值?
【问题讨论】:
标签: python image data-structures byte