Pack color channels into grayscale

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
noggs
Posts: 8
Joined: 2013-05-22T06:36:17-07:00
Authentication code: 6789

Pack color channels into grayscale

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Pack color channels into grayscale

Post 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
snibgo's IM pages: im.snibgo.com
noggs
Posts: 8
Joined: 2013-05-22T06:36:17-07:00
Authentication code: 6789

Re: Pack color channels into grayscale

Post by noggs »

Thanks for the info. Looks like it'll be easier to write a standalone tool for this!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Pack color channels into grayscale

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply