Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Easy PIL question

Reply
Thread Tools

Easy PIL question

 
 
Adam W.
Guest
Posts: n/a
 
      02-16-2008
I know there is an easy way to do this, but I can't figure it out, how
do I get the color of a pixel? I used the ImageGrab method and I want
to get the color of a specific pixel in that image. If you know how
to make it only grab that pixel, that would also be helpful.
Basically I'm trying to make a:
if pixel == color:
do_this()
else:
pass

And have it do this as fast as my pc can handle (that is why only
grabbing 1px would be helpful)
 
Reply With Quote
 
 
 
 
Gary Herron
Guest
Posts: n/a
 
      02-16-2008
Adam W. wrote:
> I know there is an easy way to do this, but I can't figure it out, how
> do I get the color of a pixel? I used the ImageGrab method and I want
> to get the color of a specific pixel in that image. If you know how
> to make it only grab that pixel, that would also be helpful.
> Basically I'm trying to make a:
> if pixel == color:
> do_this()
> else:
> pass
>
> And have it do this as fast as my pc can handle (that is why only
> grabbing 1px would be helpful)
>

Try image.getpixel((x,y)) to retrieve the pixel at (x,y).

Gary Herron


 
Reply With Quote
 
 
 
 
bearophileHUGS@lycos.com
Guest
Posts: n/a
 
      02-16-2008
Gary Herron:
> Try image.getpixel((x,y)) to retrieve the pixel at (x,y).


If the OP needs to access many pixels, then he can use the load()
method on the image object, and then read/write pixels (tuples of 3
ints) using getitem []

import Image
im = Image....
img = im.load()
img[x,y] = ...
.... = img[x,y]

I don't know why the image object itself can't have the __getitem__/
__setitem__

Bye,
bearophile
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PIL: problem to convert an image array to PIL format Sverre Python 2 12-17-2009 04:33 PM
Stripping audio from qa DVD. Easy or not so easy? GJ Computer Support 1 05-23-2007 02:03 AM
Easy PIL Question? pinkfloydhomer@gmail.com Python 2 10-30-2006 11:35 AM
[PIL] is there a downloadable docs for PIL Egor Bolonev Python 2 12-24-2004 11:05 AM
easy to look at and easy to maintain web page menuing system. Hazzard ASP .Net 2 04-06-2004 03:51 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57