P
P
Pavel-a87avfdv87isrh57ghh2020-06-04 20:41:05
Python
Pavel-a87avfdv87isrh57ghh, 2020-06-04 20:41:05

How to increase shades of red, green, blue in Pillow?

Can you please tell me how to increase or decrease the shades of red, green, blue in Pillow?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vitamark, 2020-06-05
@Pavel-a87avfdv87isrh57ghh

Any image with multiple channels can be divided into channels
. Then apply the Image.eval() method to them, something like this:

from PIL import Image

img = Image.open("путь к картинке")

channels = img.split()
channels[0] = Image.eval(
    channels[0],
    lambda x: min(x * 2, 255)
) # увеличиваем значение красного (0) в два раза
img = Image.merge(img.mode, channels)

An increase of 2 times is naturally shown only as an example, there can be any operation, the main thing is to check that the value is in the range [0, 255] and is an integer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question