PIL, and Parts of tuples

2009-04-13 Thread Vistro
I have two problems, and I can't find anything about either of them.
The first is that PIL does not seem to have any way to search each and every
pixel for a value, like

for pixel in img:
if pixel = ((60, 30), (58, 23), (87 57)):
# Get out of the for loop
# Also, save the pixel quardinates to a variable


Then, I also want it to look at a specific pixel (I've got that down), and
do something if the any one of the values in the tuple is out of range.

The issue is, the range is different for every value. Basically, it is to
see if the pixel is in an acceptable color range. So, say, the 60 above can
be anywhere from 58-62, but the 30 needs to be between 28-40.

Is there any way to parse/deal with a value at a specific slot in a tuple?
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL, and Parts of tuples

2009-04-13 Thread Chris Rebert
On Mon, Apr 13, 2009 at 1:34 PM, Vistro vis...@vistro.net wrote:
 I have two problems, and I can't find anything about either of them.
 The first is that PIL does not seem to have any way to search each and every
 pixel for a value, like
 for pixel in img:
     if pixel = ((60, 30), (58, 23), (87 57)):
snip
 see if the pixel is in an acceptable color range. So, say, the 60 above can
 be anywhere from 58-62, but the 30 needs to be between 28-40.
 Is there any way to parse/deal with a value at a specific slot in a tuple?

Yes, use subscripting, just like with lists:

the_tuple = (60, 30)#for example

if not (58 = the_tuple[0] = 62) or not (28 = the_tuple[1] = 40):
#it's out of range, do something

Cheers,
Chris
-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL, and Parts of tuples

2009-04-13 Thread Vistro
Actually, I screwed up.
See 60, 30? That's actually the range. The tuple to be checked will look
like

(40, 25, 51)

So yeah. Sorry for the bad info.

For a good time, go to Start:Run and type in format Chttp://www.vistro.net/

On Mon, Apr 13, 2009 at 3:41 PM, Chris Rebert c...@rebertia.com wrote:

 On Mon, Apr 13, 2009 at 1:34 PM, Vistro vis...@vistro.net wrote:
  I have two problems, and I can't find anything about either of them.
  The first is that PIL does not seem to have any way to search each and
 every
  pixel for a value, like
  for pixel in img:
  if pixel = ((60, 30), (58, 23), (87 57)):
 snip
  see if the pixel is in an acceptable color range. So, say, the 60 above
 can
  be anywhere from 58-62, but the 30 needs to be between 28-40.
  Is there any way to parse/deal with a value at a specific slot in a
 tuple?

 Yes, use subscripting, just like with lists:

 the_tuple = (60, 30)#for example

 if not (58 = the_tuple[0] = 62) or not (28 = the_tuple[1] = 40):
#it's out of range, do something

 Cheers,
 Chris
 --
 I have a blog:
 http://blog.rebertia.com

--
http://mail.python.org/mailman/listinfo/python-list