Determine transparent pixels and generate alpha channel

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?".
Post Reply
mhoehn@hotmail.de
Posts: 5
Joined: 2010-02-08T06:47:10-07:00
Authentication code: 8675309

Determine transparent pixels and generate alpha channel

Post by mhoehn@hotmail.de »

Is there a command line sequence that let me figure out if an image has fully transparent pixels?
And is it possible to generate an alpha channel for this image where all fully transparent pixels are black and all solid pixels are white?
It should be possible that semi transparent pixels should get gray in the alpha channel. The more a pixel is transparent in the image the darker the gray level for the representing pixel in the alpha channel should be.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Determine transparent pixels and generate alpha channel

Post by GreenKoopa »

mhoehn@hotmail.de wrote: And is it possible to generate an alpha channel for this image where all fully transparent pixels are black and all solid pixels are white?
It should be possible that semi transparent pixels should get gray in the alpha channel. The more a pixel is transparent in the image the darker the gray level for the representing pixel in the alpha channel should be.
Two of many options:

Code: Select all

convert in.png -alpha extract alpha1.png
convert in.png -channel matte -separate +channel -negate alpha2.png
mhoehn@hotmail.de wrote: Is there a command line sequence that let me figure out if an image has fully transparent pixels?
I'm not clear what form you would like the answer to take. Here is one option that gives you a count of the fully transparent pixels:

Code: Select all

convert alpha1.png -threshold 0 -format "%c" histogram:info:
Post Reply