Skip to content

Instantly share code, notes, and snippets.

@christianp
Created February 28, 2015 17:58
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 christianp/9116466cf56b62eb9300 to your computer and use it in GitHub Desktop.
Save christianp/9116466cf56b62eb9300 to your computer and use it in GitHub Desktop.
number of white pixels in an image of a Norwegian flag 1000 pixels tall - https://twitter.com/wacnt/status/567836059054186496
from PIL import Image
f=Image.open(r"2000px-flag_of_Norway.svg.png") # http://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Flag_of_Norway.svg/2000px-Flag_of_Norway.svg.png
white = 0
scale = f.size[1]/1000.0
for r,g,b,a in f.getdata():
if (r,g,b)==(255,255,255):
white += 1
white/(scale*scale)
@christianp
Copy link
Author

247338

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment