"Invert" transparency

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
autoblinker
Posts: 1
Joined: 2011-05-27T16:44:24-07:00
Authentication code: 8675308

"Invert" transparency

Postby autoblinker » 2011-05-27T18:17:21-07:00

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

User avatar
fmw42
Posts: 15150
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA
Contact:

Re: "Invert" transparency

Postby fmw42 » 2011-05-27T19:30:29-07:00

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.

User avatar
anthony
Posts: 8736
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia
Contact:

Re: "Invert" transparency

Postby anthony » 2011-05-28T01:05:04-07:00

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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/


Return to “Users”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests