title: How to replace all RGB values in an Numpy Image Arrray based on an Target Pixel
body: <p>I have an Image in an Numpy Array.
  I will replace an specific Color with Black and all others in White.
  For loops are to slow and my numpy condition ist not working.</p>
  
  <p>All pixels that matches an array --> [121, 112, 131] must complete replace with another array --> [0, 0, 0]</p>
  
  <p>All other with --> [255, 255, 255]</p>
  
  <p>My results ends up with overseen pixels that matches with the First Channel [True, False, False]</p>
  
  <p>Sorry for bad spelling, i hope my code ist better to understand.</p>
  
  <p><strong>My example result:</strong></p>
  
  <pre><code>import numpy as np
  from scipy import misc
  
  file = misc.face()
  img = np.array(file)
  
  target_color = [121, 112, 131]
  true_color = [0, 0, 0]
  false_color = [255, 255, 255]
  
  true_mask = np.all(img == target_color, axis=2)
  false_mask = np.all(img != target_color, axis=2)
  
  img[true_mask] = true_color
  img[false_mask] = false_color
  
  print(img)
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>array([[[  0,   0,   0],
          [255, 255, 255],
          [255, 255, 255],
          ...,
          [255, 255, 255],
          [255, 255, 255],
          [255, 255, 255]],
  
         [[255, 255, 255],
          [255, 255, 255],
          [255, 255, 255],
          ...,
          [255, 255, 255],
          [255, 255, 255],
          [255, 255, 255]],
  
         [[255, 255, 255],
          [255, 255, 255],
          [255, 255, 255],
          ...,
          [255, 255, 255],
          [255, 255, 255],
          [255, 255, 255]],
  
         ...,
  
         [[255, 255, 255],
          [255, 255, 255],
          [255, 255, 255],
          ...,
          [255, 255, 255],
          [255, 255, 255],
          [255, 255, 255]],
  
         [[255, 255, 255],
          [255, 255, 255],
          [255, 255, 255],
          ...,
          [121, 157,  96],
          [255, 255, 255],
          [255, 255, 255]],
  
         [[255, 255, 255],
          [255, 255, 255],
          [255, 255, 255],
          ...,
          [255, 255, 255],
          [255, 255, 255],
          [255, 255, 255]]], dtype=uint8)
  </code></pre>
  
  <p><strong>Problem:</strong></p>
  
  <p>There are Pixels left when the First Channel is equal to the target Color.</p>
  
  <pre><code>Target Pixel: [121, 112, 131]
  Overseen Pixel: [121, 157,  96]
  </code></pre>