title: Python PIL - Possible paint bucket-like tool?
body: <p>I have an image that I'm attempting to edit, using the PIL Python image library. I'm attempting to make the light-tan background transparent, by replacing pixels with a certain RGBA code with a transparent pixel. I've been looking at <a href="https://stackoverflow.com/questions/3752476/python-pil-replace-a-single-rgba-color">Python: PIL replace a single RGBA color</a>, and have edited it to allow a buffer to pick up pixels which aren't exactly the same colour. This is my current code:</p>
  
  <pre><code>data = numpy.array(im)
  red, green, blue, alpha = data.T
  
  for r in range(245, 256):
      for g in range(245, 256):
          for b in range(210, 230):
              white_areas = (red == r) &amp; (green == g) &amp; (blue == b) &amp; (alpha == 255)
              if len(data[...][white_areas.T]) != 0:
                  data[...][white_areas.T] = (0, 0, 0, 0)
  </code></pre>
  
  <p>I've found, however, that around the image, there's still a few pixels that hang around because of some colour blur, and also some around the outside edge of the image border. This is clearly visible when added to a dark background. I find that when I increase the buffer for the RGB codes, the pixel blur becomes less, except if I increase it too much, the white in the image often gets picked up accidentally. </p>
  
  <p>What would possibly be a way to remove the blur (like a paint bucket tool with high tolerance), while at the same time not increasing the time taken?</p>