我正在尝试生成一些分形图像,我可以做得很好。但是,我在保存图像时遇到了一些问题,因为它将图像保存为灰度而不是颜色。当我用python打开它们时,它会显示正确的颜色。
代码如下
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")
我使用的是MacOSX,Python2.7.5。
您正在
L
或亮度模式下创建图像。这意味着它们是灰度图像,一个色带。您需要改用
RGB
模式:这确实要求在指定像素时使用
(R, G, B)
值的元组,而不是简单的整数。ImageDraw
模块也支持使用字符串('#rrggbb'
和相关字符串)设置颜色。您没有向我们展示如何在代码中定义
col
,因此很难说明是否对RGB图像使用了正确的格式。相关问题 更多 >
编程相关推荐