1
$\begingroup$

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.

image without transparency

image with transparency (hand processed)

$\endgroup$

1 Answer 1

0
$\begingroup$

You can try the following steps:

  • traverse the image until you touch the object (by finding a point with a color significantly different from that of the white strip - check the normal variations in the white strip).

  • when you have this point, perform contour following to delineate the object, and form a closed curve.

  • make all area outside of the curve transparent (by seed filling).

  • finally, create a matte by considering the pixels inside the outline and weight their transparency proportionally to the difference between white and the local color.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.