I am printing out the R,G,B values of an image and get results like this:

(30, 0, 0)
(29, 0, 0)
(28, 0, 0)
(27, 0, 0)
(26, 0, 0)
(25, 0, 0)
(24, 0, 6)
(23, 0, 0)
(22, 0, 0)
(21, 0, 0)

That is just a partial list of the values but you can see that in the one grouping it has (24,0,6) which is what I'm after. How can I get just that group or any others like it to print out, instead of the entire list? I'm assuming I need an if statement with > 0 but am not sure how to implement it. This is the initial code:

from PIL import Image
i = Image.open('Img.bmp')
for pixel in i.getdata():
    print pixel
i_getdata_test = [ \
(30, 0, 0), \
(29, 0, 0), \
(28, 0, 0), \
(27, 0, 0), \
(26, 0, 0), \
(25, 0, 0), \
(24, 0, 6), \
(23, 0, 0), \
(22, 0, 0), \
(21, 0, 0) ]

for pixel in i_getdata_test:
   print pixel
   ##  0, 1, and 2 are the memory offsets for
   ##  the three integers in the tuple
   if pixel[2] > 0:
      print "          we want this one"
    
## if you want to explore what the "2" means,
## then uncomment the lines below
##print "\n"
##for pixel in i_getdata_test:
##   print pixel[0], "-->", pixel[1], "-->", pixel[2]

Works great, thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.