-1

How can I do a check to see if the value of whatever is in (x, x, x) is below for example 5

for i in range(img.size[0]):  # for every pixel:
    for j in range(img.size[1]):
        if pixels[i,j] != (0, 0, 0) and (1, 0, 0) and (0, 1, 0) and (0, 0, 1) and (1, 1, 0) and (0, 1, 1) and (1, 0, 1) and (1, 1, 1) and (1, 1, 2) and (1, 2, 1) and (2, 1, 1) and (2, 2, 1) and (1, 2, 2) and (2, 1, 2) and (2, 2 ,2):  # if not black:
            pixels[i,j] = (255, 255, 255)  # change to white
jps
  • 20,041
  • 15
  • 75
  • 79
  • 2
    Your question is unclear. Try provide more information about what you're trying to achieve and what the problem is. – Wahalez Jul 29 '21 at 10:10
  • Your code doesn't work at the moment. `if pixels[i, j] ...` is wrong. See [this question](https://stackoverflow.com/q/15112125/3279716) – Alex Jul 29 '21 at 10:13
  • `if x == (0,0,0) or (1,0,0) ... :` is equal to `if (x == (0,0,0)) or (1,0,0) ` which is always `True` as a non empty tuple is Truthy. Use `if x not in ( (1,0,0),(0,1,0), ... )` or check it programatically as Netwave suggested – Patrick Artner Jul 29 '21 at 10:25

1 Answers1

0

Just check your components by iterating over the tuple:

...
if not any(value <= 5 for value in pixels[i,j]):
...
Netwave
  • 40,134
  • 6
  • 50
  • 93