[Image-SIG] remove an image background using PIL
Laura & Edward Cannon
cannon.el at gmail.com
Fri May 29 17:03:30 CEST 2009
One way to get rid of a single color background is to get the
background color (look at the upper left pixel) and then compare every
pixel to it. If they are the same, make it transparent, otherwise
leave it be. This obviously only works if nothing in the foreground is
colored the same as the background, but I have had good success with
this sort of method in the pygame world for making sprites.
On Thu, May 28, 2009 at 1: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.
> thanks a lot
> On Thu, May 28, 2009 at 1:43 PM, Fredrik Lundh <fredrik at pythonware.com>
>> On Thu, May 28, 2009 at 10:22 PM, Peter Yen <colorpyen at gmail.com> wrote:
>> > Is there any sample code to use PIL to remove the image background and
>> > make
>> > it transparent? Any help and advice is highly appreciated.
>> Depends on what the background is. The further it is from "a single
>> known color", the harder it gets.
> Image-SIG maillist - Image-SIG at python.org
More information about the Image-SIG