0

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
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by kiddo39
0
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]
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.