Re: [Image-SIG] remove an image background using PIL
On Thu, May 28, 2009 at 10:53 PM, Peter Yen colorp...@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 markup: ## # (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 # pixel. 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 code. /F ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] remove an image background using PIL
Peter Yen colorp...@gmail.com wrote: 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. I once wrote a (GPL'd) C module that fairly reliably extracts the background of a photograph of a drawing on paper. It is essentially the same as PIL's floodfill but it follows shallow gradients. The public git browser[1] seems to be broken right now, but if this sounds like what you need download a tarball[2], and look for the expand_region function in the img-c directory. [1] https://savannah.nongnu.org/git/?group=tetuhi [2] http://sourceforge.net/project/showfiles.php?group_id=217385 Douglas ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] remove an image background using PIL
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 -peter On Thu, May 28, 2009 at 1:43 PM, Fredrik Lundh fred...@pythonware.comwrote: On Thu, May 28, 2009 at 10:22 PM, Peter Yen colorp...@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. /F ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig