Jump to content

Extracting image from white background


Recommended Posts

Hello, I have a question regarding the techniques of extracting a colored image from white backgroud.

 

One simple method for doing this is using magic wand to select the white background and then deleting it, but this is actually the worst method in my experience, because it leaves the edges rough with some white left depending on the tolerance setting. Another method is to use fill tool using transparency and the overwrite setting, and this is a better method, because it makes the edges much nicer. Last method I know is manually removing the white with brush tool using transparency+overwrite, but this is very time consuming and prone to error.

 

However when you think about it, you can think about this problem like it's actually an image on top layer and under it there's another layer with full white color. They're just merged.

A thing I've been wondering is, would it be possible through some clever trickery/math to successfuly reverse such merge? Basically think extracting the top image from white backgrounds as if they were just merged moments ago. Would such a thing be possible to do with Paint.net?

Link to post
Share on other sites
2 hours ago, kamov said:

...would it be possible through some clever trickery/math to successfuly reverse such merge?

Yes it would!

Use the Plugin Index to search for plugins like Grim Color Reaper, Kill Color Keeper, Cut Color, Color Clearer. Do a generic "color" search to find quite a few more that I can't remember off the top of my head. 

 

Alternatively, follow this @TrevorOutlaw video tutorial on how to use remove.bg that also works for more complex backgrounds: 

 

Xkds4Lh.png

Link to post
Share on other sites

The problem with using that idea directly is that there will be pixels in the foreground part of the image that contain a lot of white. Removing the white from them -- which is the inverse operation from blending the two layers -- leaves them partially transparent. My Color Clearer plugin does that inverse operation, but as I say, it doesn't give the result you want because it will make foreground pixels non-opaque.

 

What I think woud be a useful plugin is one that uses a flood fill (like the Magic Wand and Paint Bucket do) to erase all the contiguous pixels of a selected color, then applies the Color Clearer's algorithm to all the pixels the fill touches, but doesn't erase. That might achieve the result you're after. I plan to write a plugin like that eventually, but  have several other plugins I want to finish first. (If anyone else wants to write a plugin like that first, they're welcome to the idea.)

 

Here's a suggestion that might produce similar results, though I haven't tried it (because I just thought of it).

 

Duplicate the image.

Run the Color Clearer, with the erase color set to white, on the lower layer.

On the upper layer, use the Magic Wand with a very low tolerance  to select the white background.

Erase the selection, leaving  the foreground with a jaggy edge.

Run dpy's AA's Assistant on the top image. That will smooth and also slightly erode the edge of the foreground image.

Merge the layers.

 

The idea is that the Color Clearer image will provide the the edge, but with the white removed, while the top layer will provide the fully-opaque interior pixels. It seems like it should work -- but of course not everything that seems like it should work actually does.

 

EDIT: Another thing try instead of AA's Assistant is Distort>Morphology, with the Erode Mode and a Width and Height of 3.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...