繁体   English   中英

PIL图像以灰度保存

[英]PIL images are saving in grayscale

我正在尝试生成一些分形图像,我可以做得很好。 但是,在保存图像时我遇到了一些问题,因为它将它们保存为灰度而不是颜色。 当我在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")

我正在使用macOS X,Python 2.7.5。

您正在L或Luminance模式下创建图像。 这意味着它们是灰度图像,一条颜色带。

您需要使用RGB模式:

image = Image.new("RGB", (SIZE, SIZE))

这确实要求您在指定像素时使用(R, G, B)值的元组,而不是简单的整数。 ImageDraw模块也支持使用字符串设置颜色( '#rrggbb'和相关)。

您没有向我们展示如何在代码中定义col ,因此如果您使用正确的RGB图像格式,则很难说明。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM