Last active
October 1, 2019 16:08
-
-
Save bradmontgomery/613861 to your computer and use it in GitHub Desktop.
Use PIL to find a list of colors 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
import Image | |
def get_color_list(path_to_image): | |
""" | |
Returns a list of tuples for RGB colors: (R, G, B) | |
This is gonna be slow and memory-intensive. Use at your own risk. | |
Requires PIL | |
""" | |
def _get_color(t): return t[1] | |
im = Image.open(path_to_image) | |
colors = [] | |
colors = map(_get_color, im.getcolors(im.size[0]*im.size[1])) | |
colors = list(set(colors)) # ditch duplicate colors | |
return colors | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment