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

<p>Example.</p>

<p>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?</p>

<p>As already mentioned in <a href="http://stackoverflow.com/questions/138250/how-can-i-read-the-rgb-value-of-a-given-pixel-in-python">this</a> question, by using <code>Pillow</code> you can do the following:</p>

<pre><code>from PIL import Image
im = Image.open('image.jpg', 'r')
</code></pre>

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

<pre><code>width, height = im.size
pixel_values = list(im.getdata()) 
print(im.format, im.size, im.mode)
</code></pre>

<p>The <code>format</code> attribute identifies the source of an image. If the image was not read from a file, it is set to None. The <code>mode</code> 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.</p>

python