Get Pixel count using RGB values in Python
Question: I have to find count of pixels of RGB which is using by RGB values. So i need
logic for that one.

Example.

i have image called image.jpg. That image contains width = 100 and height =
100 and Red value is 128. Green is 0 and blue is 128. so that i need to find
how much RGB pixels have that image. can anyone help?


Answer: As already mentioned in [this](http://stackoverflow.com/questions/138250/how-
can-i-read-the-rgb-value-of-a-given-pixel-in-python) question, by using
`Pillow` you can do the following:

    
    
    from PIL import Image
    im = Image.open('image.jpg', 'r')
    

If successful, this function returns an Image object. You can now use instance
attributes to examine the file contents:

    
    
    width, height = im.size
    pixel_values = list(im.getdata()) 
    print(im.format, im.size, im.mode)
    

The `format` attribute identifies the source of an image. If the image was not
read from a file, it is set to None. The `mode` attribute defines the number
and names of the bands in the image, and also the pixel type and depth. Common
modes are “L” (luminance) for greyscale images, “RGB” for true color images,
and “CMYK” for pre-press images.

