简体   繁体   English

使用 Pillow 降低图像的亮度

[英]Low the brightness of an Image using Pillow

I'm using Pillow for a project, and I really want to create an effect like in the following Image, look:我正在将 Pillow 用于一个项目,我真的很想创建如下图所示的效果,请看:

向自己扔鸡

In this picture, you see like the background Image is opaque, I don't know if that's the word I need to use.在这张图片中,你看到背景图片是不透明的,我不知道我是否需要使用这个词。 What I want to do is that the text is brighter than the background Image, this is a nice effect.我想要做的是文本比背景图像更亮,这是一个不错的效果。

Can I duplicate this effect in Pillow?我可以在 Pillow 中复制这种效果吗? and if so, what would be the function?如果是这样,它的功能是什么? Thank you a lot.非常感谢。 I know this is a broad question, but since I don't know how to even ask the question the proper way, I will accept any suggestion that will lead me to the right path.我知道这是一个广泛的问题,但由于我什至不知道如何以正确的方式提出问题,我会接受任何可以引导我走向正确道路的建议。

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

Based on the comment of @martineau基于@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)

As stated in the docs you can use Pillow's ImageEnhance module for lowering or increasing the brightness of an image.文档中所述,您可以使用 Pillow 的ImageEnhance模块来降低或增加图像的亮度。

Minimal Working Example (MWE):最小工作示例(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")

So to get the text of the image brighter than the background image, first apply the effect to the image, then add the text.所以要让图片的文字比背景图片更亮,先把效果应用到图片上,然后再添加文字。

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

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