Page 1 of 1

Pack color channels into grayscale

Posted: 2013-12-06T02:18:38-07:00
by noggs
I want to take an RGBA png input, extract the G & B channels, and pack them into a single 8-bit grayscale image. In other words the final 8-bit grayscale PNG output has the source Green channel packed into the lower 4 bits, the Blue channel packed into the upper 4 bits.

I can see how to extract the G and B channels as grayscale, but I'm stuck on scaling/biasing the channels to pack them together. Does anyone know if this is possible using the command line?

Cheers, Noel

Re: Pack color channels into grayscale

Posted: 2013-12-06T02:51:57-07:00
by snibgo
It can probably be done entirely within IM, but possibly very messy. The easiest way would be to process the image in a script, C program or whatever.

Something similar was asked in this forum not long ago: viewtopic.php?f=2&t=23199

Re: Pack color channels into grayscale

Posted: 2013-12-06T06:58:44-07:00
by noggs
Thanks for the info. Looks like it'll be easier to write a standalone tool for this!

Re: Pack color channels into grayscale

Posted: 2013-12-06T07:39:24-07:00
by snibgo
Yes, I think so. The RAW: and TXT: formats are easy to read and write. See http://www.imagemagick.org/Usage/files/#txt and http://www.imagemagick.org/Usage/formats/#rgb . Or PBM: http://www.imagemagick.org/Usage/formats/#pbmplus .

A C program to do what you want would be almost trivial.