Skip to content

Instantly share code, notes, and snippets.

@skiptomyliu
Created March 9, 2017 04:03
Show Gist options
  • Save skiptomyliu/1adebdd7bf4030865f9e2628ec79e041 to your computer and use it in GitHub Desktop.
Save skiptomyliu/1adebdd7bf4030865f9e2628ec79e041 to your computer and use it in GitHub Desktop.
def average_color(image):
w,h = image.size
x0,y0 = (0,0)
x1,y1 = (w,h)
r,g,b = 0,0,0
area = w*h
for x in range(x0, x1):
for y in range(y0, y1):
cr,cg,cb = image.getpixel((x,y))
r+=cr
g+=cg
b+=cb
return (r/area, g/area, b/area)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment