Can ImageMagick batch-process channel subtraction and channel remapping for infrared false color?

Asked 12/12/2022

1 views

2 answers

0

I want to emulate Kodak Aerochrome/EIR from full-spectrum digital files by applying an IRG-to-RBG transform in batch mode. Specifically, I need to subtract the blue channel from the red and green channels, then remap channels so blue becomes red, red becomes green, and green becomes blue. Photoshop’s Channel Mixer can do this, but I’d prefer a command-line workflow for batch processing. Can ImageMagick perform this kind of channel math and channel swap? If so, what command or operator should I look at? If not, is there another open-source CLI tool suited to it?

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

3y ago

2 Answers

2

Check out the -color-matrix operator to see if it meets your needs.

From your description, I think the following RGB matrix transform will work:

 0  0  1   (R =  B)
 1  0 -1   (G =  R - B)
 0  1 -1   (B =  G - B)

But from the graphic in your post, it looks like the following RGB matrix transform is what you're after:

0    0     1      (R = B)
0.8  0    -0.8    (G = 0.8*R - 0.8*B = 0.8 * (R - B))
0    0.96 -0.96   (B = 0.96*G - 0.96*B = 0.96 * (G - B))

So your command would look like (using the 2nd matrix, for example):

magick <input_file> -color-matrix ` 0    0     1
                                    0.8 -0.8   0
                                    0    0.96 -0.96 ` <output_file>

Note that color channels are non-negative. Because you are subtracting channels, you might need to make sure your resulting values are non-negative as well, by adding a constant offset for the channels that had subtraction. The color matrix can accommodate 3 additional columns: 'Black', 'Alpha', and Constant, in that order. I assume your Black and Alpha channels are zero. In order to specify Constant, you have to specify '0' for Black and Alpha. So the final matrix might look like:

0    0     1     0  0  0     (R = B)
0.8  0    -0.8   0  0  0.8   (G = 0.8R - 0.8B + 0.8)
0    0.96 -0.96  0  0  0.96  (B = 0.96G - 0.96B + 0.96)

You'll have to experiment to see if you need to specify the constant value.

Originally by user11924. Source · Licensed CC BY-SA 4.0

user11924

3y ago

0

AI Answer

Generated from our catalog & community — verify before relying on it.

Yes. ImageMagick can do this with -color-matrix, which applies a linear transform to the RGB channels and can both remap and subtract channels.

From the community example, a basic IRG→RBG-style transform is:

  • R' = B
  • G' = R - B
  • B' = G - B

That corresponds to a matrix like: 0 0 1 1 0 -1 0 1 -1

Example command: magick input.jpg -color-matrix "0 0 1 1 0 -1 0 1 -1" output.jpg

A scaled version suggested in the answers is: magick input.jpg -color-matrix "0 0 1 0.8 -0.8 0 0 0.96 -0.96" output.jpg

This is the right ImageMagick feature to explore for batch processing. One caveat: channel values can’t go below zero, so any subtraction that would produce negative values may be clipped unless you work in a format/workflow that preserves more headroom. But for the operation you described, -color-matrix is the relevant tool.

UniqueBot

AI

3y ago

Your Answer