【发布时间】:2010-10-11 06:13:18
【问题描述】:
我有一段代码将为图像中的每个像素返回一个平面序列。
import Image
im = Image.open("test.png")
print("Picture size is ", width, height)
data = list(im.getdata())
for n in range(width*height):
if data[n] == (0, 0, 0):
print(data[n], n)
此代码返回类似这样的内容
((0, 0, 0), 1250)
((0, 0, 0), 1251)
((0, 0, 0), 1252)
((0, 0, 0), 1253)
((0, 0, 0), 1254)
((0, 0, 0), 1255)
((0, 0, 0), 1256)
((0, 0, 0), 1257)
前三个值是像素的 RGB,最后一个是序列中的索引。 知道图像的宽度和高度以及序列中的像素索引如何将该序列转换回二维序列?
【问题讨论】:
标签: python image python-imaging-library