Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
432 B
12
Indexable
Never
from PIL import Image


def get_brightness(rgb_tuple: tuple) -> int:
    return 0.3 * rgb_tuple[0] + 0.59 * rgb_tuple[1] + 0.11 * rgb_tuple[2]


im = Image.open('img.png')
pixels = list(im.getdata())
width, height = im.size
for index in range(width * height):
    if get_brightness(pixels[index]) > 128:
        pixels[index] = (0, 255, 0)
    else:
        pixels[index] = (0, 0, 255)
im.putdata(pixels)
im.show()