Page 1 of 1

"Invert" transparency

Posted: 2011-05-27T18:17:21-07:00
by autoblinker
Hi,

My problem should be easy to solve as it isn't very complicated but everything I tried didn't work.

I have a image like this:
Image
It has a transparent background and one solid color (white). The rounded borders have alpha transparency.

Now to my problem:
I want to "invert" the transparent and the white area so that the transparent area gets white and the white area gets transparent. The semi-transparent areas are my problem.

The things I tried:

Code: Select all

convert 1cut.png +level-colors red, out.png
--> the alpha channel gets lost so the shape is inaccurate.

Code: Select all

convert 1cut.png -transparent white out.png
--> the semi-transparent area isn't touched, so this way doesn't work either


Any hints how to solve this problem?

Thanks

Re: "Invert" transparency

Posted: 2011-05-27T19:30:29-07:00
by fmw42
not sure I fully understand. so try these. the issue may still be your partially transparent areas. if so, you will need to threshold the alpha channel or use -morphology to erode some of it.


convert 1cut.png -channel a -negate +channel 1cut_nega.png

convert 1cut.png -channel rgba -negate +channel 1cut_nega2.png


if either of these is not what you want, please clarify further.

Re: "Invert" transparency

Posted: 2011-05-28T01:05:04-07:00
by anthony
I assume you want the areas that is currently transparent white!
You must remember that transparenct pixels have a undefined color, as such you will need to ensure that they are white.

So Negate the alpha channel (as Fred previously pointed out) then set all pixels white.

Code: Select all

convert 1cut.png -channel a -negate +channel -fill white -colorize 100% 1cut_nega.png
Note the order of the two actions does not matter as you are appling them to each of the channel types in the image separately. But it is important that you ensure all pixels get colors white.

An alternative is just make sure all fully transparency pixels are white (before negating) using...

Code: Select all

convert 1cut.png -background white -alpha background -channel a -negate +channel 1cut_nega.png
See http://www.imagemagick.org/Usage/maskin ... background
In this can the final +channel setting does not actually matter as you save the image, but it is a good thing to do if you want to continue processing the image, instead of saving.