Created
April 24, 2020 02:42
-
-
Save beans42/db25031b6e29a399ccae03799fe09882 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
def greyscale(img: Image) -> Image: | |
img_width, img_height = img.size | |
pixels = img.load() | |
#for every pixel | |
for i in range(img_width): | |
for j in range(img_height): | |
rgb = pixels[i, j] | |
brightness = int(rgb[0] * 0.2126 + rgb[1] * 0.7152 + rgb[2] * 0.0722) #relative luminance = 0.2126R + 0.7152G + 0.0722B | |
pixels[i, j] = ( brightness, brightness, brightness ) | |
return img | |
image = Image.open(input() + ".png") | |
image = greyscale(image) | |
image.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment