PIL in Python complains that there are no 'size' attributes to a PixelAccess, what am I doing wrong?
Question: I am trying to program an application that will loop through every pixel of a
given image, get the rgb value for each, add it to a dictionary (along with
amount of occurences) and then give me rundown of the most used rgb values.

However, to be able to loop through images, I need to be able to fetch their
size; this proved to be no easy task.

According to the [PIL
documentation](http://effbot.org/imagingbook/image.htm#tag-Image.Image.size),
the Image object should have an attribute called 'size'. When I try to run the
program, I get this error:

    
    
    AttributeError: 'PixelAccess' object has no attribute 'size'
    

this is the code:

    
    
    from PIL import Image
    import sys
    
    '''
    TODO: 
    - Get an image
    - Loop through all the pixels and get the rgb values
    - append rgb values to dict as key, and increment value by 1
    - return a "graph" of all the colours and their occurances
    
    TODO LATER:
    - couple similar colours together
    '''
    
    SIZE = 0
    
    def load_image(path=sys.argv[1]):
        image = Image.open(path)
        im = image.load()
        SIZE = im.size
        return im
    
    keyValue = {}
    
    # set the image object to variable
    image = load_image()
    print SIZE
    

Which makes no sense at all. What am I doing wrong?


Answer: `image.load` returns a pixel access object that does not have a `size`
attribute

    
    
    def load_image(path=sys.argv[1]):
        image = Image.open(path)
        im = image.load()
        SIZE = image.size
        return im
    

is what you want

[documentation](http://effbot.org/imagingbook/image.htm) for PIL

