Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from PIL import Image
import math
# creating a image object
img = Image.open('selenagomez.png')
px = img.load()
height, width = img.size
new_image = Image.new(img.mode, img.size)
for row in range(0, height):
for column in range(0, width):
red, blue, green = px[row, column]
avg = math.floor((red + blue + green)/3)
new_image.putpixel((row, column), (avg, avg, avg))
new_image.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.