Analysis of images using PIL in Python
Question: I found this code:

    
    
    import PIL
    from PIL import Image
    from matplotlib import pyplot as plt
    
    im = Image.open('./color_gradient.png')  
    w, h = im.size  
    colors = im.getcolors(w*h)
    
    def hexencode(rgb):
     r=rgb[0]
     g=rgb[1]
     b=rgb[2]
     return '#%02x%02x%02x' % (r,g,b)
    
    for idx, c in enumerate(colors):
        plt.bar(idx, c[0], color=hexencode(c[1]),edgecolor=hexencode(c[1]))
    plot.show()
    

For the exact link one can look here-[Plot image color histogram using
matplotlib](http://stackoverflow.com/questions/12182891/plot-image-color-
histogram-using-matplotlib)

My questions are what are the meaning of the axes, and how can I generate a
table out these values? I would like to run some statistics, like percent of
green, or red in the picture...

Thanks


Answer: From the [PIL Documentation](http://effbot.org/imagingbook/image.htm):

> **getcolors**
>
> im.getcolors() => a list of (count, color) tuples or None
>
> im.getcolors(maxcolors) => a list of (count, color) tuples or None

The Y axis in the referred graph is the pixel count of that colour and the X
axis comprises the (unsorted?) list of colours in the graph.

