EchoReaper Posted April 20, 2016 Share Posted April 20, 2016 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. Quote Link to comment Share on other sites More sharing options...
ReMake Posted April 20, 2016 Share Posted April 20, 2016 Try Cut Color by xmario. Play with Tolerance in color. Quote Link to comment Share on other sites More sharing options...
Ego Eram Reputo Posted April 20, 2016 Share Posted April 20, 2016 Hey EchoReaper - welcome to the paint.net forum 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 ) 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. 1 Quote ebook: Mastering Paint.NET | resources: Plugin Index | Stereogram Tut | proud supporter of Codelab plugins: EER's Plugin Pack | Planetoid | StickMan | WhichSymbol+ | Dr Scott's Markup Renderer | CSV Filetype | dwarf horde plugins: Plugin Browser | ShapeMaker Link to comment Share on other sites More sharing options...
MJW Posted April 20, 2016 Share Posted April 20, 2016 (edited) 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): 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 April 20, 2016 by MJW Quote Link to comment Share on other sites More sharing options...
Ego Eram Reputo Posted April 20, 2016 Share Posted April 20, 2016 Like I said, a fascinating subject! HSV Eraser is definitely better than GCR but does not look as accurate as Make Transparent (arguably ) <someone should write this up...> Quote ebook: Mastering Paint.NET | resources: Plugin Index | Stereogram Tut | proud supporter of Codelab plugins: EER's Plugin Pack | Planetoid | StickMan | WhichSymbol+ | Dr Scott's Markup Renderer | CSV Filetype | dwarf horde plugins: Plugin Browser | ShapeMaker Link to comment Share on other sites More sharing options...
MJW Posted April 20, 2016 Share Posted April 20, 2016 (edited) 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 April 20, 2016 by MJW Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.