Fra*_*rci 12 text numpy python-imaging-library
我的Python库PIL存在一个基本问题.我有一些.txt文件只包含排列在矩阵中的0和1值.我已经使用PIL中包含的函数Image.fromarray()转换了图像中的"二进制"数据.如果我将它乘以255,我的数据格式会生成黑白图像,这对我来说很好.现在我想使用PIL中包含的相应文本函数向图像添加一些文本,但我希望该文本被着色.显然,我无法做到这一点,因为从fromarray获得的图像具有灰度色彩图.我该怎么改变它?
Fra*_*ois 16
您可以从单色的RGB图像中获取这样的图像:
from PIL import Image
from numpy import eye                                                            
arr = (eye(200)*255).astype('uint8') # sample array
im = Image.fromarray(arr) # monochromatic image
imrgb = im.convert('RGB') # color image
imrgb.show()