Extract 5bpp 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
andrey
Posts: 10
Joined: 2010-03-01T09:39:57-07:00
Authentication code: 8675308

Extract 5bpp alpha channel

Post by andrey »

I have a png file with alpha channel. I'm extracting it's alpha channel as raw bytes with this command:

Code: Select all

stream -map a input.png output.raw
Is there any way to reduce alpha values range from 0-255 to 0-31 (so for example 255 becomes 31, and 127 becomes 15) in this process?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Extract 5bpp alpha channel

Post by fmw42 »

I am not sure if this is really what you want. But you can try -evaluate divide (or perhaps -fx with bitshift operator) on the alpha channel only. But the bit depth will still be 8-bits, only the graylevel range will be reduced to the desired range (so will be about 8 times darker)

http://www.imagemagick.org/Usage/transform/#evaluate
http://www.imagemagick.org/script/fx.php
andrey
Posts: 10
Joined: 2010-03-01T09:39:57-07:00
Authentication code: 8675308

Re: Extract 5bpp alpha channel

Post by andrey »

Thanks, doing

Code: Select all

convert input.png -channel alpha -fx "a*31/255" output.png
before stream does the trick, still I don't like that "*31/255" part: I'd rather use >> operation (thinking I'm working with integer channel values), but since I got a real number in range [0..1] as input, I can't.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Extract 5bpp alpha channel

Post by fmw42 »

convert input.png -channel alpha -fx "a*31/255" output.png
what is "a" in your formula? do you really mean "u" for the value of the first image?


The following will be faster (-evaluate vs -fx):

ratio=`convert xc: -format "%[fx:31/255]" info:`
convert input.png -channel alpha -evaluate multiply $ratio output.png
andrey
Posts: 10
Joined: 2010-03-01T09:39:57-07:00
Authentication code: 8675308

Re: Extract 5bpp alpha channel

Post by andrey »

fmw42 wrote:what is "a" in your formula?
Docs on -fx you linked above say
a = alpha
, and it works.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Extract 5bpp alpha channel

Post by fmw42 »

that is the channel and usually it would be referenced as u.a where u references the particular input image, but perhaps "a" is sufficient when you only have one input image or want to process the alpha channel of each input image. I have never tried it that way.
Post Reply