2

I'd like to know how to (in code) merge multiple grayscale images into a single 16-bit RGB color image, using color look-up tables (LUTs).

In ImageJ, one is able to take, say, 7 different 16-bit grayscale images, and merge their values into a single color composite.

ImageJ Merge Channels

It's trivial for the case where you have <= 3 images, and the desired mapping of input image to color channel is exclusive. That is, if I had three 16-bit greyscale images, and I wanted image 1 to be red, 2 to be blue, and 3 to be green, well, I'd just set the corresponding output image pixels to be RGB(input1, input2, input3).

However, in ImageJ there's an option to merge more than three color channels, including colors that are themselves combinations of R, G, or B. It's possible to select five greyscale images with the following desired otuput color:

Input image: desired color in output image
==
input 1: Red
input 2: Green
input 3: Blue
input 4: Magenta // Combination of R + B
input 5: Cyan // Combination of R + G

Let's say the LUTs mapping input (greyscale) to output (RGB) are:

Red:     input -> (input, 0,     0    )
Green:   input -> (0,     input, 0    )
Blue:    input -> (0,     0,     input)
Magenta: input -> (input, 0,     input)
Cyan:    input -> (input, input, 0    )

In the output image, should create the composite by simply averaging over all input images that contribute to a color channel? Or is there a more sophisticated approach? My naïve approach would be:

Output pixel = R: (input1+input4+input5)/3
               G: (input2+input5)/2
               B: (input3+input4)/2

I'm not sure what the right algorithm to use is for blending colors as ImageJ does. In fact, the code is here but is impenetrable to me: https://github.com/imagej/ImageJA/blob/3ed2e1a1d785eda3c9dfdb330030aee968c242b8/src/main/java/ij/plugin/RGBStackMerge.java

Thanks in advance for any pointers!

0

1 Answer 1

2

I found the answer by toying with it -- it turns out ImageJ uses simple addition of color channels (with a clamp), rather than averaging them. Averaging the R, G, B values from inputs produces dull values, while summing and clamping produces bright ones, which is what I was looking for.

See this post for more information: Algorithm for Additive Color Mixing for RGB Values

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.