Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
from PIL import Image
import math
# creating a image object
img ='selenagomez.png')
px = img.load()
height, width = img.size
new_image =, 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))
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.