title: Detect color and remove that color from image
body: <p>I have image with kind of light purple image in background and character in dark blue. My goal is to identify text from the image. So I'm trying to remove light purple color from background so that my image will be free of noise, but I can't find the exact color code for that image as it is somewhat different everywhere, so I'm not able to mask image. Here's my code</p>
  
  <pre><code>import numpy as np
  from PIL import Image
  
  im = Image.open('capture.png')
  
  im = im.convert('RGBA')
  data = np.array(im)
  
  rgb = data[:,:,:3]
  color = [27, 49, 89]   # Original value to be mask
  black = [0,0,0, 255]
  white = [255,255,255,255]
  mask = np.all(rgb == color, axis = -1)
  data[mask] = black
  data[np.logical_not(mask)] = white
  
  new_im = Image.fromarray(data)
  new_im.save('new_file.png')
  
  </code></pre>
  
  <p>So I thought if I can remove color in all particular color range like [R:0-20, G:0-20, B:80-100] maybe that'll will work. Can someone tell me how can i do that. </p>
  
  <p>Any other suggestion to solve this problem will also be appreciated.</p>