Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-如何在不使用第三方库的情况下读取图像像素?_Python_Image_Data Structures_Byte - Fatal编程技术网

Python-如何在不使用第三方库的情况下读取图像像素?

Python-如何在不使用第三方库的情况下读取图像像素?,python,image,data-structures,byte,Python,Image,Data Structures,Byte,使用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.pn

使用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)

这将产生一个字节对象,但是如何获得图像的实际像素值呢?

使用标准库从图像中读取像素字节没有简单的解决方案

您当然可以自己编写这样的模块,但这意味着理解PNG格式、处理压缩图像数据等等。当你完成的时候,你已经…开发出了你自己能力较弱的版本

您最好使用现有模块来获取所需的数据