0

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?

Prem Rexx
  • 95
  • 1
  • 10
  • 2
    Have you looked at the `pillow` library? – Jon Clements Oct 13 '16 at 11:35
  • 3
    Check this out: http://stackoverflow.com/questions/138250/how-can-i-read-the-rgb-value-of-a-given-pixel-in-python – gplayer Oct 13 '16 at 11:36
  • Do you mean you want to find out how many pixels have a certain colour? Or how many pixels there are in the image in total (which would be width*height)? – Anton Oct 13 '16 at 13:08

1 Answers1

0

As already mentioned in this 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.

Community
  • 1
  • 1
Kian
  • 1,319
  • 1
  • 13
  • 23