Replace color with transparency.. or "remove a color"
Replace color with transparency.. or "remove a color"
Hey guys!
Great forums. My first question here is -- hopefully -- a very simple one.
I want to remove the white out of my bitmap image, resulting in 100 % transparency where white was before. How to do this?
I found the "Replace color" extension. There one can define "replace color RRGGBB" "by color RRGGBB". Hence, I cannot define any transparency there. Are there other ways to do what I want? Why don't you allow for "by color RRGGBBAA" in the replace dialogue?
Thanks a lot,
Jan-Philip
Great forums. My first question here is -- hopefully -- a very simple one.
I want to remove the white out of my bitmap image, resulting in 100 % transparency where white was before. How to do this?
I found the "Replace color" extension. There one can define "replace color RRGGBB" "by color RRGGBB". Hence, I cannot define any transparency there. Are there other ways to do what I want? Why don't you allow for "by color RRGGBBAA" in the replace dialogue?
Thanks a lot,
Jan-Philip
Re: Replace color with transparency.. or "remove a color"
Replace color doesn't work on bitmaps, you'll have to use another method.
Try clipping - create an object that covers the bitmap only over the areas that aren't white, lower its opacity so you can see through it and clip the image with the object in the end.
Try clipping - create an object that covers the bitmap only over the areas that aren't white, lower its opacity so you can see through it and clip the image with the object in the end.
just hand over the chocolate and nobody gets hurt
Inkscape Manual on Floss
Inkscape FAQ
very comprehensive Inkscape guide
Inkscape 0.48 Illustrator's Cookbook - 109 recipes to learn and explore Inkscape - with SVG examples to download
Inkscape Manual on Floss
Inkscape FAQ
very comprehensive Inkscape guide
Inkscape 0.48 Illustrator's Cookbook - 109 recipes to learn and explore Inkscape - with SVG examples to download
Re: Replace color with transparency.. or "remove a color"
Okay, thank you
Two related questions on this:
1) Replacing colors in bitmaps seems to be a quite simple problem.. iterate over all pixels and change some of them. I don't know much about the technical structure of Inkscape, but could this be easily implemented as an additional effect/extension? Perhaps this would be a nice task for me or somebody else to contribute to Inkscape.
2) I interprete "Replace color doesn't work on bitmaps" as replace color only works with inkscape/vector/svg objects. Why isn't it allowed to define "replace by color RRGGBBAA" at this point?
Two related questions on this:
1) Replacing colors in bitmaps seems to be a quite simple problem.. iterate over all pixels and change some of them. I don't know much about the technical structure of Inkscape, but could this be easily implemented as an additional effect/extension? Perhaps this would be a nice task for me or somebody else to contribute to Inkscape.
2) I interprete "Replace color doesn't work on bitmaps" as replace color only works with inkscape/vector/svg objects. Why isn't it allowed to define "replace by color RRGGBBAA" at this point?
Re: Replace color with transparency.. or "remove a color"
The reason Inkscape can't select colors, is because of the nature of vector graphics, which does not recognize pixels. Raster graphics programs achieve this by selecting every pixel with white in it. But with vectors, no pixels, so no way to select the white areas.
That said, I believe there is some sort of trick by which this can be done. Unfortunately, I can't remember what it is But maybe someone else can tell you? Manipulating the XML code, I think? However, if you want alpha transparency, where there is some solid white, which would be fully transparent, and "shades" of white which would be partiallly transparent, while "not white" would be opaque, you'll do better with a Mask, rather than a Clip. If your bitmap is a photo or something like it, this will be very difficult to do with Inkscape (if not impossible). But if it is a rather simple line drawing, like a cartoon, it should be "doable" ( ) especially if it's all solid white and you want only full transparency.
We get this type of question so much, that I'm in the process of writing kind of an overview, to put in an FAQ for this forum. It's not ready to post yet though.
That said, I believe there is some sort of trick by which this can be done. Unfortunately, I can't remember what it is But maybe someone else can tell you? Manipulating the XML code, I think? However, if you want alpha transparency, where there is some solid white, which would be fully transparent, and "shades" of white which would be partiallly transparent, while "not white" would be opaque, you'll do better with a Mask, rather than a Clip. If your bitmap is a photo or something like it, this will be very difficult to do with Inkscape (if not impossible). But if it is a rather simple line drawing, like a cartoon, it should be "doable" ( ) especially if it's all solid white and you want only full transparency.
We get this type of question so much, that I'm in the process of writing kind of an overview, to put in an FAQ for this forum. It's not ready to post yet though.
Basics - Help menu > Tutorials
Manual - Inkscape: Guide to a Vector Drawing Program
Inkscape Community - Inkscape FAQ - Gallery
Inkscape for Cutting Design
Manual - Inkscape: Guide to a Vector Drawing Program
Inkscape Community - Inkscape FAQ - Gallery
Inkscape for Cutting Design
-
- Posts: 215
- Joined: Thu Aug 21, 2008 4:08 am
- Location: Belgium
Re: Replace color with transparency.. or "remove a color"
I think there is room for one or two new filters there because filters also work very well on bitmaps. If you are interested you could try to create them yourself and if they work well of course they could be integrated with the others. Don't hesitate to pm me about that.
And if you want to test the latest filters experiments they are here : http://www.openclipart.org/detail/84433 Only backup the already existing filters.svg file from Inkscape filters folder and replace it with this one.
ivan
And if you want to test the latest filters experiments they are here : http://www.openclipart.org/detail/84433 Only backup the already existing filters.svg file from Inkscape filters folder and replace it with this one.
ivan
Re: Replace color with transparency.. or "remove a color"
You'll have to use GIMP or some other raster editor to edit bitmaps, you can even right-click on an image and open it in a raster editor. Inkscape has limited raster abilities, find them under Extensions > Raster.
When using replace color opacity is preserved, only color is changed, you can consider them separate properties if you like. I guess there'd had to be an additional box where to enter opacity value inside Replace color dialogue. It's this way because the extension author created it that way lol Report a bug if you want something changed or added https://bugs.launchpad.net/inkscape/
Hey Ivan! Got any tips on what primitives to use to create a filter that makes all white areas transparent?
BTW I tried the new filters they are a great addition, and it's nice they are all marked as new makes it easier to explore.
When using replace color opacity is preserved, only color is changed, you can consider them separate properties if you like. I guess there'd had to be an additional box where to enter opacity value inside Replace color dialogue. It's this way because the extension author created it that way lol Report a bug if you want something changed or added https://bugs.launchpad.net/inkscape/
Hey Ivan! Got any tips on what primitives to use to create a filter that makes all white areas transparent?
BTW I tried the new filters they are a great addition, and it's nice they are all marked as new makes it easier to explore.
just hand over the chocolate and nobody gets hurt
Inkscape Manual on Floss
Inkscape FAQ
very comprehensive Inkscape guide
Inkscape 0.48 Illustrator's Cookbook - 109 recipes to learn and explore Inkscape - with SVG examples to download
Inkscape Manual on Floss
Inkscape FAQ
very comprehensive Inkscape guide
Inkscape 0.48 Illustrator's Cookbook - 109 recipes to learn and explore Inkscape - with SVG examples to download
-
- Posts: 215
- Joined: Thu Aug 21, 2008 4:08 am
- Location: Belgium
Re: Replace color with transparency.. or "remove a color"
prkos wrote: Hey Ivan! Got any tips on what primitives to use to create a filter that makes all white areas transparent?
BTW I tried the new filters they are a great addition, and it's nice they are all marked as new makes it easier to explore.
This kind of filter already exists : Transparency tool/Light eraser but it's progressive and based on lightness and not color.
However you can easily modify it : open the Filters Editor, then apply the filter, then add a new Effect Color Matrix, then in the fourth line at the bottom of the Color Matrix, change the two last numbers for example from "1" and "0" to "10" and "-1" You will see that transparency is now much more confined to white or very pale areas.
ivan
Re: Replace color with transparency.. or "remove a color"
Thanx Ivan!
I tried your tip and it works on the image I tested but not on the yellow area. Increasing the first of the last two numbers to 20 or more fixed it.
But the more I increase it the light areas turn more opaque (as expected right?)
One issue emerges with matting - matted pixels along the dark object edges are also visible when the image is over a dark background. Do you know of any voodoo that can address this?
Thank you for all of the work you do on filters, I feel like I can never thank you enough
I tried your tip and it works on the image I tested but not on the yellow area. Increasing the first of the last two numbers to 20 or more fixed it.
But the more I increase it the light areas turn more opaque (as expected right?)
One issue emerges with matting - matted pixels along the dark object edges are also visible when the image is over a dark background. Do you know of any voodoo that can address this?
Thank you for all of the work you do on filters, I feel like I can never thank you enough
just hand over the chocolate and nobody gets hurt
Inkscape Manual on Floss
Inkscape FAQ
very comprehensive Inkscape guide
Inkscape 0.48 Illustrator's Cookbook - 109 recipes to learn and explore Inkscape - with SVG examples to download
Inkscape Manual on Floss
Inkscape FAQ
very comprehensive Inkscape guide
Inkscape 0.48 Illustrator's Cookbook - 109 recipes to learn and explore Inkscape - with SVG examples to download
-
- Posts: 215
- Joined: Thu Aug 21, 2008 4:08 am
- Location: Belgium
Re: Replace color with transparency.. or "remove a color"
Thanks to you too for using them
I am not sure but I think the edges problem will not be addressed before Inkscape rendering use more than 8 bit per color channel. However you could try to overlay your first filter (please do group your object with itself before applying a second filter to keep the filters separated in the Filters Editor) with a second one in ABC sub-menu called Edge cleaner and which does some kind of feathering. Increasing the gaussian blur amount does one part of the work but not all unfortunately.
ivan
P.S. New version of Filters alternate here : http://www.openclipart.org/detail/84595
I added the control by Color Matrix in Light eraser and other Transparency utilities. And I also added a fluorescent option in the Bicolorize filter : go to the bottom of the tree in the Filters Editor and drag and drop the first entry handle of the last Composite to the Color Matrix just above.
ivan
I am not sure but I think the edges problem will not be addressed before Inkscape rendering use more than 8 bit per color channel. However you could try to overlay your first filter (please do group your object with itself before applying a second filter to keep the filters separated in the Filters Editor) with a second one in ABC sub-menu called Edge cleaner and which does some kind of feathering. Increasing the gaussian blur amount does one part of the work but not all unfortunately.
ivan
P.S. New version of Filters alternate here : http://www.openclipart.org/detail/84595
I added the control by Color Matrix in Light eraser and other Transparency utilities. And I also added a fluorescent option in the Bicolorize filter : go to the bottom of the tree in the Filters Editor and drag and drop the first entry handle of the last Composite to the Color Matrix just above.
ivan
-
- Posts: 215
- Joined: Thu Aug 21, 2008 4:08 am
- Location: Belgium
Re: Replace color with transparency.. or "remove a color"
prkos wrote:Thanx Ivan!
I tried your tip and it works on the image I tested but not on the yellow area. Increasing the first of the last two numbers to 20 or more fixed it.
But the more I increase it the light areas turn more opaque (as expected right?)
One issue emerges with matting - matted pixels along the dark object edges are also visible when the image is over a dark background. Do you know of any voodoo that can address this?
Thank you for all of the work you do on filters, I feel like I can never thank you enough
Light eraser and Light eraser negative are improved and the problem with matted pixels along edges is almost solved in this release : http://www.openclipart.org/detail/84655
To isolate more precisely the white areas, increase the fourth value in the fourth line in the last Color matrix.
ivan
Re: Replace color with transparency.. or "remove a color"
Do we still need to add the Color Matrix manually?
BTW I now see two Alpha repaint and Light eraser, negative filters in the list.
BTW I now see two Alpha repaint and Light eraser, negative filters in the list.
just hand over the chocolate and nobody gets hurt
Inkscape Manual on Floss
Inkscape FAQ
very comprehensive Inkscape guide
Inkscape 0.48 Illustrator's Cookbook - 109 recipes to learn and explore Inkscape - with SVG examples to download
Inkscape Manual on Floss
Inkscape FAQ
very comprehensive Inkscape guide
Inkscape 0.48 Illustrator's Cookbook - 109 recipes to learn and explore Inkscape - with SVG examples to download
-
- Posts: 215
- Joined: Thu Aug 21, 2008 4:08 am
- Location: Belgium
Re: Replace color with transparency.. or "remove a color"
prkos wrote:Do we still need to add the Color Matrix manually?
BTW I now see two Alpha repaint and Light eraser, negative filters in the list.
No. It's inside now !
Re: Replace color with transparency.. or "remove a color"
ivan louette wrote:No. It's inside now !prkos wrote:Do we still need to add the Color Matrix manually?
Ivan - would you consider adding the default values (identity matrix) for the feColorMatrix component explicitly in 'filters.svg'? Otherwise Inkscape floods the console [1] whenever a 'Light Eraser' filter is active and the current view is updated, with error messages like
** (inkscape-bin:65152): WARNING **: ColorMatrix: values parameter error. Wrong size: 0.
Apparently some functions that process the filter components don't know about default values used for rendering and prefer to complain about missing parameters ;-) The visible result doesn't change though as far as I can tell.
[1] You can check the console messages on Windows with inkscapec.exe (if you use the installer package for 0.48) or just launch inkscape from the command line if you use the 7z package for 0.48 or 0.48+devel (the command line wrapper is now integrated in Inkscape - just that it was forgotten to be added to the installer package 0.48.0-1)
-
- Posts: 215
- Joined: Thu Aug 21, 2008 4:08 am
- Location: Belgium
Re: Replace color with transparency.. or "remove a color"
Thanks. I am afraid this is a wrong rendering message and not a true filters problem. I don't know if it could be changed inside the filters.svg file. Did you already fill a bug on Launchpad ?
ivan
ivan
Re: Replace color with transparency.. or "remove a color"
I think we mean the same thing - adding the identity matrix would be redundant but make Inkscape "happy", while still conforming to the SVG specification and without changing the rendered result of the preset filter (please test with attached SVG file).ivan louette wrote:I am afraid this is a wrong rendering message and not a true filters problem.
If the warning is what I think it is (complaining about the missing 'values' attribute instead of falling back to the default value (identity)) - Inkscape at some point has to be fixed to know about the default values for filter primitive attributes without complaining about missing parameters - somewhere in a subroutine handling the filter stuff.
In my understanding, the warning can be avoided by changes in 'filters.svg' (not "fixed" though, afaiu).ivan louette wrote:I don't know if it could be changed inside the filters.svg file.
Not yet. I was interested in how you interpret the warning, first. OTOH several of the current preset filters produce a lot of console messages… warnings mainly. I'm not sure yet how to systematically test and then investigate the cause for each, nor do I know if this is really necessary.ivan louette wrote:Did you already fill a bug on Launchpad ?
(yes, personally I think console warnings are there for a reason, usually, and should be addressed ).
- Attachments
-
- light-eraser-negative-1.svg
- [updated]
- (54.32 KiB) Downloaded 236 times
-
- Posts: 215
- Joined: Thu Aug 21, 2008 4:08 am
- Location: Belgium
Re: Replace color with transparency.. or "remove a color"
That explains because Filters Editor works somewhat minimalistic ; try to do that while XML Editor is open :
- If you simply add a Color Matrix to your filter it doesn't specify the type but Inkscape interprets it by default as a Matrix
- If you add a Color Matrix and then change for example to HueRotate and then come back to Matrix, then it indicates Matrix as the type but it doesn't give any value
- If you add a Color Matrix, then change the values and come back to default values, then it indicates these default values
Thus what is present in filters.svg reflects my process in creating the filters. Of course I could change that, but then perhaps the best should be to change Filters Editor Behavior ! I was wrong this morning
ivan
- If you simply add a Color Matrix to your filter it doesn't specify the type but Inkscape interprets it by default as a Matrix
- If you add a Color Matrix and then change for example to HueRotate and then come back to Matrix, then it indicates Matrix as the type but it doesn't give any value
- If you add a Color Matrix, then change the values and come back to default values, then it indicates these default values
Thus what is present in filters.svg reflects my process in creating the filters. Of course I could change that, but then perhaps the best should be to change Filters Editor Behavior ! I was wrong this morning
ivan
Re: Replace color with transparency.. or "remove a color"
I also just noticed that GIMP (2.6.10) and rsvg-view (both use the same library, librsvg, for rendering SVG) do not display the 'Light eraser' filter effect (dropping the filtered object completely) if the default values for the last feColorMatrix component is missing.
Squiggle (Batik 1.7) OTOH renders both versions of the filter as expected (and the same as in Inkscape), as well as web browsers like Firefox (3.6.9) and Opera (10.61).
-> other SVG renderers (also) fail to handle missing default (fallback) values gracefully.
Screenshots with previously attached SVG file, but with both filter effects enabled (as described in the text).
Batik 1.7:
GIMP 2.6.10:
rsvg-view 2.26.2:
Squiggle (Batik 1.7) OTOH renders both versions of the filter as expected (and the same as in Inkscape), as well as web browsers like Firefox (3.6.9) and Opera (10.61).
-> other SVG renderers (also) fail to handle missing default (fallback) values gracefully.
Screenshots with previously attached SVG file, but with both filter effects enabled (as described in the text).
Batik 1.7:
GIMP 2.6.10:
rsvg-view 2.26.2:
Re: Replace color with transparency.. or "remove a color"
Agreed - Inkscape's Filter Editor needs to be fixed to write filter definitions that Inkscape can interpret and render without console warnings about missing parameters (or Inkscape must be fully aware of the default (fallback) values if attributes/values are omitted).ivan louette wrote:Thus what is present in filters.svg reflects my process in creating the filters. Of course I could change that, but then perhaps the best should be to change Filters Editor Behavior
IIRC there are already some reports filed about the filter editor's incorrect handling of parameters - I'll check the bug tracker again to see if this fits one of them, or if it needs to be reported separately (at the moment, specifically the issue with the values for the 'matrix' attribute of feColorMatrix).
-
- Posts: 215
- Joined: Thu Aug 21, 2008 4:08 am
- Location: Belgium
Re: Replace color with transparency.. or "remove a color"
I think the most important thing is to match svg specifications. And I am not sure Filters Editor is wrong in this specific case (while it is wrong sometimes somewhere else).
Of course being more exigent than svg specs can be useful for some programs internally, but to my sense this is also a door open to worst exclusive (if not proprietary) behaviors.
ivan
Of course being more exigent than svg specs can be useful for some programs internally, but to my sense this is also a door open to worst exclusive (if not proprietary) behaviors.
ivan
Re: Replace color with transparency.. or "remove a color"
Is it some part of the rendering engine that emits the warnings about missing parameters? Or - since the visual result looks correct in both examples - just some parsing routine updating/constructing the filter definition (from the SVG source) internally for the renderer?ivan louette wrote:I think the most important thing is to match svg specifications. And I am not sure Filters Editor is wrong in this specific case (while it is wrong sometimes somewhere else).
-
- Posts: 215
- Joined: Thu Aug 21, 2008 4:08 am
- Location: Belgium
Re: Replace color with transparency.. or "remove a color"
In fact I don't know anything about that area. I am a visual person and thus if a filter looks like I expected in Inkscape I am glad. Afterwards, before uploading the final version of the filters.svg file on Inkscape server at the program release time it is automatically checked with a script buid by Tavmjong Bah which removes almost completely bad code. I didn't have any bad surprises after that, nothing worked differently in filters. But the version you find on OpenClipart is intermediate and not cleaned up as are the intermediate versions I upload on Inkscape server.
ivan
ivan
Re: Replace color with transparency.. or "remove a color"
ivan louette wrote:(…) before uploading the final version of the filters.svg file on Inkscape server at the program release time it is automatically checked with a script buid by Tavmjong Bah which removes almost completely bad code. I didn't have any bad surprises after that, nothing worked differently in filters. But the version you find on OpenClipart is intermediate and not cleaned up as are the intermediate versions I upload on Inkscape server.
Sorry for bothering with the implementation details then - I wasn't aware of that process ;)
-
- Posts: 215
- Joined: Thu Aug 21, 2008 4:08 am
- Location: Belgium
Re: Replace color with transparency.. or "remove a color"
No problem ! I like to be aware of every problem concerning filters and you provided very useful information there. I am not sure that Tavmjong Bah script takes account of what you remarked. I don't remember if you are a member of the devlist but you could also ask your question there.
ivan
ivan
-
- Posts: 1
- Joined: Thu Oct 25, 2012 2:26 pm
Re: Replace color with transparency.. or "remove a color"
ivan louette wrote:prkos wrote: Hey Ivan! Got any tips on what primitives to use to create a filter that makes all white areas transparent?
BTW I tried the new filters they are a great addition, and it's nice they are all marked as new makes it easier to explore.
This kind of filter already exists : Transparency tool/Light eraser but it's progressive and based on lightness and not color.
However you can easily modify it : open the Filters Editor, then apply the filter, then add a new Effect Color Matrix, then in the fourth line at the bottom of the Color Matrix, change the two last numbers for example from "1" and "0" to "10" and "-1" You will see that transparency is now much more confined to white or very pale areas.
ivan
Please suggest value for black or very dark area and one other color of your choice by transparency. I'm grateful for guidance on removing white background, however owing to inexperience with vector graphics, I 'm lost & wasting too much time on getting basics right so need help.. Thank you.