1>>> from PIL import Image
2>>> im = Image.open('polar-bear-cub.jpg')
3>>> from collections import defaultdict
4>>> by_color = defaultdict(int)
5>>> for pixel in im.getdata():
6... by_color[pixel] += 1
7>>> by_color
8defaultdict(<type 'int'>, {(11, 24, 41): 8, (53, 52, 58): 8, (142, 147, 117): 1, (121, 111, 119): 1, (234, 228, 216): 4