我有一段代码将为图像中的每个像素返回一个平坦序列。在python中将平面序列转换为2d序列
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,最后一个是序列索引。 了解图像的宽度和高度以及像素索引的顺序如何将该序列转换回2d序列?
谢谢。有效 – giodamelio 2010-10-10 22:16:09