There are a few approaches for extracting colors from an image.
Shameless plug: I helped write a library called colorific to do it: https://github.com/99designs/colorific
More about how it works here: http://99designs.com/tech-blog/blog/2012/05/11/color-analysi...
Clustering techniques can also work quite well: http://charlesleifer.com/blog/using-python-and-k-means-to-fi...