[Image-SIG] remove an image background using PIL
fredrik at pythonware.com
Sun May 31 19:27:53 CEST 2009
On Thu, May 28, 2009 at 10:53 PM, Peter Yen <colorpyen at gmail.com> wrote:
> Hi Fredrik,
> Thanks for your quick response. The background is unknown at the time of
> processing. Actually I don't need a very accurate methodology to remove all
> background, removing partially is good enough.
> imagick has method like floodfill, curious how to do that with PIL.
There's a floodfill function in ImageDraw that might be good enough
for you. I'm not sure it's documented, but here's the PythonDoc
# (experimental) Fills a bounded region with a given color.
# @def floodfill(image, xy, value, border=None)
# @param image Target image.
# @param xy Seed position (a 2-item coordinate tuple).
# @param value Fill color.
# @param border Optional border value. If given, the region consists of
# pixels with a color different from the border color. If not given,
# the region consists of pixels having the same color as the seed
It's pure Python, so if you want more complex rules for determining
what's background and not, you can always grab a copy and tweak the
More information about the Image-SIG