Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python PIL: color index to RGB

Tags:

python

image

following this link i was able to load and read pixels from a .gif. That question specifically askes for a RGB value, but the accepted (and most voted answer) that I used as reference gets me to get an int as value. What is it? I guess some sort of index, but how to convert it to a proper rgb value? Thanks

[..]
img = Image.open(GIF_FILENAME)
pix = img.load()
for i in range(5):
    print img.getpixel((i, 0))
    # this returns me like 78, 65.. how to get RGB?
[..]
like image 932
pistacchio Avatar asked Mar 02 '10 14:03

pistacchio


People also ask

Is Pil image RGB or BGR?

The basic difference between OpenCV image and PIL image is OpenCV follows BGR color convention and PIL follows RGB color convention and the method of converting will be based on this difference.

What is Getpixel in Python?

getpixel(self, xy): Returns the pixel at x,y. The pixel is returned as a single. value for single band images or a tuple for multiple band images. param xy: The pixel coordinate, given as (x, y).


1 Answers

img = Image.open(GIF_FILENAME)
rgbimg = img.convert('RGB')
for i in range(5):
    print rgbimg.getpixel((i, 0))
like image 169
John La Rooy Avatar answered Sep 28 '22 23:09

John La Rooy