因此,我将要绘制的曲线的 x 和 y 值作为浮点值保存在 numpy 数组中。现在,我想将它们四舍五入到最接近的 int,并将它们绘制为空 PIL 图像中的像素值。省略我实际填充 x 和 y 向量的方式,以下是我们正在使用的内容:
# create blank image
new_img = Image.new('L', (500,500))
pix = new_img.load()
# round to int and convert to int
xx = np.rint(x).astype(int)
yy = np.rint(y).astype(int)
ordered_pairs = set(zip(xx, yy))
for i in ordered_pairs:
pix[i[0], i[1]] = 255
这给了我一条错误消息:
File "makeCurves.py", line 105, in makeCurve
pix[i[0], i[1]] = 255
TypeError: an integer is required
但是,这对我来说毫无意义,因为.astype(int)
应该将这些小狗转换为整数。如果我使用pix[int(i[0]], int(i[1])]
它可以工作,但这很糟糕。
为什么我.astype(int)
没有被 PIL 识别为 int?