Created
March 9, 2017 04:03
-
-
Save skiptomyliu/1adebdd7bf4030865f9e2628ec79e041 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
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