[英]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.