With the Python Imaging Library, you can convert an image to a limited palette and then ask it about colors. Something like (did not check the following):
from PIL import Image
im = Image.open("foo.jpg")
im = im.convert("P", Image.ADAPTIVE, colors=16)
C Image.ADAPTIVE, im.convertselects the 16 most common colors, also known as the palette. Then you can access them using im.palette.
source
share