Skip to content

Instantly share code, notes, and snippets.

@Allwin12
Created June 1, 2020 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Allwin12/c0030bbba006bfaf43dcf33913d40ded to your computer and use it in GitHub Desktop.
Save Allwin12/c0030bbba006bfaf43dcf33913d40ded to your computer and use it in GitHub Desktop.
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