[Image-SIG] Help on accessing pixels values

Douglas S. Blank dblank at brynmawr.edu
Fri Jun 23 20:06:21 CEST 2006


Dom,

You should consult the very good on-line documentation (search for
"python image library"). Here is a hint:

import Image
im = Image.open("myimage.jpg")
im.getpixel((0,0)) # position (0,0)
im.putpixel((0,0), (0,0,0) ) # black

-Doug

On Fri, 2006-06-23 at 18:55 +0200, bestdomdom wrote:
> Hello Everybody,
> 
> First please forgive me for asking such a basic question but I am a newbie
> to Python, to programming and I am alone with my IT worries.
> I would like to access pixels values in order to make some computations but
> with the 1.1.6 PIL, I don't understand.
> As an example, here is what I do:
> 
> import Image
> im = Image.open("myimage.jpg")
> pixel=im.load()
> print pixel [0,0] # to see the value of pixel[0,0]
> x=(0,0,0) #black in RGB
> pixel[0,0]=x # to set the first pixel in black
> 
> This gives me an error : "TypeError: unsubscriptable object".
> I believe I am doing something wrong ;(
> 
> May someone just explain me with such an example what I should do.
> Thanks in advance for your help
> 
> Dom
> 
> _______________________________________________
> Image-SIG maillist  -  Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig
> 
-- 
Douglas S. Blank       Computer Science
Assistant Professor    Bryn Mawr College
(610)526-6501          http://cs.brynmawr.edu/~dblank




More information about the Image-SIG mailing list