Jump to content

Is there any way to remove a color from a flat image?

Recommended Posts

Let's assume we have an image with a solid-color background like this:



I want to remove that solid-color background -- essentially un-flatten the image, and make it as if the red background layer never existed. The magic wand tool at tolerance=0 wouldn't work because then it wouldn't remove the red from under the transparent parts of the image. I know it's possible to remove the solid background though, because I've done it before by manually selecting colors/transparencies and drawing them over the background to see if the color matched a part of the image. Is there any sort of built-in behavior or a plugin to automate this for me? What I'm looking for is something that loops through all of the pixels and makes them the color/transparency they would have been if the background wasn't there.

Link to comment
Share on other sites

Hey EchoReaper - welcome to the paint.net forum :D

This is a fascinating topic. There are quite a few different plugins which will do the job - with subtle variances.

Here's another option: Grim Color Reaper. It works a little differently that Color Cut as you can see by the output image below.


Choose the red background as the Primary color (use the Color Picker :ColorPickerTool: ) then run the GCR plugin from Effects > Color.





And finally, Make Transparent.




Produces almost exactly the same results as GCR, if anything the result is slightly closer.


To test the color extraction, I added the red background back in as a new layer then flattened. Set the modified layer blend mode to XOR to identify the differences from the original.The resultant images are not exactly the same as the original - but very close.




   Grim Color Reaper          Make Transparent

Here are the XOR differences on white to make them more obvious. Black indicates exactly the same color as the original in the XOR'd images above, so I've removed black to leave just the areas where the images are different.


  • Upvote 1
Link to comment
Share on other sites

Perhaps you could try the HSV Eraser. Set the color to erase to the red background color. The easiest was to do that is to use the Color Picker tool to set the Primary Color, then choose Primary Color as the HSV Eraser Match Color. Set the Hue Tolerance to 1.0, the Portion of Non-Erased Color to Preserve to 1.0, and check Gray Matches All Hues.


Example (shown against PDN's checkerboard background):   ErasedWithHsvEraser_zpstrwqeq8t.png


EDIT: Not to be immodest, but HSV Eraser's algorithm is better than Grim Reaper's; it removes the background color more completely. I'm not sure about Make Transparent, but my erased version seems to have more of the background color eliminated. When Portion of Non-Erased Color to Preserve is set to 1.0, HSV Eraser makes the colors as transparent as possible, while still producing the original colors when alpha blended to the original background color.


EDIT 2: I realized I had forgotten I needed to set the Hue Tolerance to 1.0 and to check Gray Matches All Hues, which meant that some of the pixels were only partially erased. I fixed the instructions, and substituted an updated image. After comparing the results now that I'm doing it correctly, I believe Make Transparent uses the same basic algorithm as HSV Eraser. Since Make Transparent is considerably easier to use for this specific task, I recommended using it.

Edited by MJW
Link to comment
Share on other sites

Like I said, a fascinating subject!

HSV Eraser is definitely better than GCR but does not look as accurate as Make Transparent (arguably :lol:)


<someone should write this up...>

Link to comment
Share on other sites

I don't really agree that HSV Eraser is less accurate. If an erased version is set against a layer with the original background color, the result is in almost every case visually indistinguishable from the original. The alpha-blended version may be up to one bit different in some color components due to rounding, but is otherwise identical. You could achieve "more accurate" results by only removing pixels that exactly match the background color, while leaving the remaining pixels unaltered and opaque, but that would be contrary to the objective of removing the background color as if it were a layer that was blended against.The goal of HSV Eraser's algorithm is to make the colors as transparent as possible.


EDIT: I may possibly be able to reduce the number of one-bit errors by slightly modifying the computation. I'll probably look into that.


EDIT 2: As mentioned in an edit to my original comment, I really messed up my original attempt, and have corrected the mistakes. I now believe Make Transparent probably uses the same method as HSV Eraser to remove as much of the background color as possible.

Edited by MJW
Link to comment
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.

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...