Created
July 3, 2020 22:22
-
-
Save Caffe1neAdd1ct/9c62fab8b850ddd455891159224b8155 to your computer and use it in GitHub Desktop.
Counts background pixels in an image
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
#!/usr/bin/env python | |
from PIL import Image | |
image = Image.open("image.jpg") | |
bg = image.getpixel((0,0)) | |
width, height = image.size | |
bg_count = next(n for n,c in image.getcolors(width*height) if c==bg) | |
img_count = width*height - bg_count | |
img_percent = img_count*100.0/width/height | |
print(img_percent) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment