I'm trying to convert images that have a single object with an outline to a transparent background. I'm currently using the image/png package in golang but can switch to any language thats more appropriate for the task.
What i'm trying so far is to floodfill the white surrounding background with transparency, convert the outline to a transparency and then do the floodfill again to catch the white area surrounding the image. This isn't working well so far. I've tried using a two phase approach where I do a floodfill with a distance tolerance to get the white area outside of the outline. A similar approach to removing the outline then another tolerance floodfill to get the rest of the white area inside the outline.
My approaches have been too simple when it comes to the outline though and while I get parts of it, I can't come up with an approach that gets the whole outline taking into account the various shading. One approach, came closest to working which is to "erase" the area within a fixed number pixels away from the outer white area but even that had problems.
Here are examples of before and after images that demonstrate what i'm trying to accomplish. This seems like it should be simple but i'm stuck.
Thanks in advance for any help.