Page 1 of 1

Extract 5bpp alpha channel

Posted: 2011-01-31T05:20:02-07:00
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?

Re: Extract 5bpp alpha channel

Posted: 2011-01-31T10:52:32-07:00
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

Re: Extract 5bpp alpha channel

Posted: 2011-02-08T08:22:16-07:00
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.

Re: Extract 5bpp alpha channel

Posted: 2011-02-08T11:23:01-07:00
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

Re: Extract 5bpp alpha channel

Posted: 2011-02-09T07:15:53-07:00
by andrey
fmw42 wrote:what is "a" in your formula?
Docs on -fx you linked above say
a = alpha
, and it works.

Re: Extract 5bpp alpha channel

Posted: 2011-02-09T10:28:38-07:00
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.