Recreate third color channel with 2 channels and grayscale image.

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
coolperez8
Posts: 23
Joined: 2016-03-11T07:27:11-07:00
Authentication code: 1151

Recreate third color channel with 2 channels and grayscale image.

Post by coolperez8 » 2017-12-16T09:35:19-07:00

Let's say I have a grayscale version of the image, and 2 of the color channels. Assuming that the fx command below was used to generate the grayscale, how can I recreate the third channel and piece the channels together in one command?

Code: Select all

-fx '(r+g+b)/3'

snibgo
Posts: 10937
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Recreate third color channel with 2 channels and grayscale image.

Post by snibgo » 2017-12-16T10:11:43-07:00

You need to know which channel is missing, so they can be combined in the correct order. I'll assume it is the blue channel.

First, find an expression for the missing channel. Fairly obviously:

blue = 3*gray - red - green

The IM operation that can make one image from many inputs, each with a known weight, is "-poly".
snibgo's IM pages: im.snibgo.com

Post Reply