title: How to select all non-black pixels in a NumPy array?
body: <p>I am trying to get a list of an image's pixels that are different from a specific color using NumPy.</p>
  
  <p>For example, while processig the following image: </p>
  
  <p><a href="https://i.stack.imgur.com/08gNN.png" rel="noreferrer"><img src="https://i.stack.imgur.com/08gNN.png" alt="enter image description here"></a></p>
  
  <p>I've managed to get a list of all black pixels using:</p>
  
  <pre><code>np.where(np.all(mask == [0,0,0], axis=-1))
  </code></pre>
  
  <p>But when I try to do:</p>
  
  <pre><code>np.where(np.all(mask != [0,0,0], axis=-1))
  </code></pre>
  
  <p>I get a pretty strange result:</p>
  
  <p><a href="https://i.stack.imgur.com/0lmu8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/0lmu8.png" alt="enter image description here"></a></p>
  
  <p>It looks like NumPy has returned only the indices were R, G, and B are non-0</p>
  
  <p>Here is a minimal example of what I'm trying to do:</p>
  
  <pre><code>import numpy as np
  import cv2
  
  # Read mask
  mask = cv2.imread("path/to/img")
  excluded_color = [0,0,0]
  
  # Try to get indices of pixel with different colors
  indices_list = np.where(np.all(mask != excluded_color, axis=-1))
  
  # For some reason, the list doesn't contain all different colors
  print("excluded indices are", indices_list)
  
  # Visualization
  mask[indices_list] = [255,255,255]
  
  cv2.imshow(mask)
  cv2.waitKey(0)
  </code></pre>