Remove White Background

Hi, long time that I don’t post here…

I’ve been helping Romu here at work where he was trying to use a JPG instead of a PNG with alpha channel.
Why he was trying to do that?
Firstly he was using PNGs but each image was around 600 kb. So he was trying somehow remove the white background from those images because saving as JPG it’s less than 60kb.

It’s not a perfect background remover, but it works with the website he’s developing.

I don’t know if there are easier or more accurate chroma-key like background removing techniques, but… here is my workaround.

The images is not from the website… it’s a Brazilian cartoon called ‘A Turma da Mônica’

Sources?
Not yet… I’m busy right now but I’ll try to explain how I did it.

1. Using ColorMatrixFilter, I converted each RGB channel to the alpha channel.
2. Using BitmapData.threshold, converted every pixel with alpha bigger than 0 to black.
3. Applyed a Blur.
4. Mask the original Bitmap using cacheAsBitmap = true;

Vote in HexoSearch Vote

5 Comments »

  1. Valck said,

    December 17, 2008 @ 2:30 pm

    Bem batuta isso, hein nego…

  2. Mr.doob said,

    December 17, 2008 @ 8:08 pm

    What about creating a PNG with the proper alpha channel and then importing it to Flash and let Flash save it as jpg? It will keep the alpha channel and will compress the colors.

    It will be bigger than 60k, but will have a perfect mask ;)

    If you need to do that with a lot of images, here it’s a script you may find useful…
    http://mrdoob.com/tools/jsfl/png2swf.jsfl

  3. keita said,

    December 17, 2008 @ 8:15 pm

    Mr.doob,

    I thought about that too, and I think it’s the best way too.
    But, this way we are able to change the images dynamically or leave it to the client to change the images.

  4. Gabriel Laet said,

    December 28, 2008 @ 1:08 pm

    If your target image is something that you have well-defined contours (like this one) – i would go with the vectorization/contour extraction process (which is pretty simple actually) to get the correct mask – and then you don’t lose white colors inside the image.

  5. Seth said,

    April 23, 2011 @ 1:52 am

    Sources?
    Not yet… I’m busy right now but I’ll try to explain how I did it.

    Have you posted the source???

RSS feed for comments on this post · TrackBack URI

Leave a Comment