0
我试图生成一些分形图像,我可以做得很好。但是,在保存图像时,我遇到了一些问题,因为它将它们保存为灰度而不是颜色。当我用python打开它们时,它显示正确的颜色。PIL图像保存为灰度
的代码如下
from PIL import Image
import ImageDraw
from scipy import misc
from array import *
import matplotlib.pyplot as plt
import scipy
image = Image.new("L",(SIZE, SIZE)) # create a image SIZE x SIZE
d = ImageDraw.Draw(image)
#iterate over x and y, setting a col value for each pixel
d.point((x, y), col) # it then colors the point (x,y)
image.save("beta"+str(alpha)+".png", "PNG")
我使用MacOS X系统,Python的2.7.5。
嗯,我正在调整代码,但更新col值,我只是将它设置为一个不同的整数值。我将研究使用RGB。那我到底应该怎样定义col?只是(价值,价值,价值)的元组? –
@DanielAbramovici:是的,一个元组可以。有关其他支持的值,请参阅[ImageDraw文档](http://effbot.org/imagingbook/imagedraw.htm)。 –
你实际上也可以使用一个整数。我在这里问完全问题(使用整数的彩色图像):http://stackoverflow.com/questions/32192671/pil-image-mode-i-is-grayscale/32200857 – Miguel