使用 Pillow 降低图像的亮度

问题描述 投票:0回答:2

我正在使用 Pillow 进行项目,我真的很想创建如下图所示的效果,请看:

To Throw a chicken at oneself

在这张图片中,你会看到背景图像是不透明的,我不知道这是否是我需要使用的词。我想做的是文字比背景图片更亮,这是一个不错的效果。

我可以在 Pillow 中复制这个效果吗?如果是的话,其功能是什么?万分感谢。我知道这是一个广泛的问题,但由于我什至不知道如何以正确的方式提出问题,所以我会接受任何引导我走上正确道路的建议。

PS。我在以下位置找到了这张图片:http://qz.com/402739/the-best-idioms-from-around-the-world-ranked/

python python-imaging-library
2个回答
10
投票

如文档中所述,您可以使用 Pillow 的 ImageEnhance

 模块来降低或增加图像的亮度。

最小工作示例(MWE):

from PIL import Image, ImageEnhance img = Image.open("image.jpg") enhancer = ImageEnhance.Brightness(img) # to reduce brightness by 50%, use factor 0.5 img = enhancer.enhance(0.5) img.show() img.save("image_darker.jpg")
因此,要使图像的文本比背景图像更亮,请先将效果应用于图像,然后添加文本。


4
投票
基于

@martineau 的评论

from PIL import Image im = Image.open('image-to-modify.jpg') source = im.split() R, G, B = 0, 1, 2 constant = 1.5 # constant by which each pixel is divided Red = source[R].point(lambda i: i/constant) Green = source[G].point(lambda i: i/constant) Blue = source[B].point(lambda i: i/constant) im = Image.merge(im.mode, (Red, Green, Blue)) im.save('modified-image.jpeg', 'JPEG', quality=100)
    
© www.soinside.com 2019 - 2024. All rights reserved.