Help! Cannot merge more than 3 channels

I have 4 RGB images, each of which represents a channel. Each is a stack of 9 slices (in z). When I use Image>Color>Merge_Channels, I can merge 3 of the channels perfectly fine. The resulting Composite shows all 3 channels superimposed and I can scroll in z, in other words, each z slice is a composite of the 3 channels for that slice.

The “Merge_Channels” tool allows you to pick up to 7 channels. However when I pick 4 channels, the Composite shows only 3 channels, and there are no slices!

What am I doing wrong? Why does it work for 3 channels but not 4, if I am doing exactly the same thing?


I have some problems to understand you data description. However you find a similar post here which might be helpful using Hyperstacks:

1 Like

This seems like it might be a bug. The following macro reproduces the issue:

type = "RGB";
newImage("HyperStack", type + " color-mode label", 400, 300, 1, 9, 1);
drawString("red", 10, 100);
newImage("HyperStack", type + " color-mode label", 400, 300, 1, 9, 1);
drawString("green", 60, 100);
newImage("HyperStack", type + " color-mode label", 400, 300, 1, 9, 1);
drawString("blue", 110, 100);
newImage("HyperStack", type + " color-mode label", 400, 300, 1, 9, 1);
drawString("cyan", 160, 100);
run("Merge Channels...", "c1=red c2=green c3=blue c5=cyan create");

But if you change the first line to:

type = "8-bit";

then the macro works as expected.

The thing about RGB images is that they have exactly three 8-bit channels “baked in” already. So while ImageJ lets you do stuff like create a “multichannel” RGB hyperstack, if you then run “Make Composite” on it, those channels get shunted to a different dimension like Z. So you may need to convert your stacks to a different type before attempting to merge them.

What do you think, @Wayne? Bug? Or intended behavior for RGB images?


Thank you ctrueden!
I don’t know if it is a bug or the expected RGB behavior, but your fix did work. For those who may have similar issues, here’s a summary of the whole process:

I have images acquired in a DeltaVision deconvolution microscope. I want to adjust the levels (brightness, contrast) of each channel individually and save them as separate images, then create a composite and save it, and finally arrange as usual for publication (C1, C2…composite) and save that as a JPG.
Here are the problems I encountered:

I can split channels fine, adjust levels and then merge again, as long as I keep the original type (16-bit). However, when I try to combine (Image>Stack>Tools>Combine"), both channels are the same color.
On the other hand, if I split channels, adjust levels, convert to RGB and merge again, then the Combine tool works fine (each channel keeps its own color), but I can only merge 3 channels successfully.

So my approach was to split channels, adjust levels, re-merge, then convert everything to RGB and combine. There is probably a better way to do it, but my understanding of image type thing (RGB, 8/16-bit etc. is very limited. If anybody sees a problem, please let me know!! I hope I am not changing my data!

Here is the macro I use. Note that it loops through all the images in a folder of choice.

// This macro processes all the images in a folder and any subfolders.

extension = ".dv";
dir1 = getDirectory("Choose Source Directory ");
dir2 = getDirectory("Choose Destination Directory ");
n = 1;

function processFolder(dir1) {
  list = getFileList(dir1);
  for (i=0; i<list.length; i++) {
    if (endsWith(list[i], "/"))
    else if (endsWith(list[i], extension))
      processImage(dir1, list[i]);

function processImage(dir1, name) {
  run("Bio-Formats Importer", "open=filename autoscale color_mode=Composite view=Hyperstack stack_order=XYCZT");

  saveAs("Tiff", "/Applications/ImageJ/Temp/active.tif");
  run("Split Channels");

  setMinAndMax(121, 900);
  saveAs("Tiff", "/Applications/ImageJ/Temp/DAPI.tif");

  setMinAndMax(100, 1600);
  saveAs("Tiff", "/Applications/ImageJ/Temp/GFP.tif");

  setMinAndMax(100, 1400);
  saveAs("Tiff", "/Applications/ImageJ/Temp/TUBULIN.tif");

  setMinAndMax(0, 1597);
  saveAs("Tiff", "/Applications/ImageJ/Temp/YOURTAG.tif");

  run("Merge Channels...", "c1=YOURTAG.tif c2=GFP.tif c3=DAPI.tif c5=TUBULIN.tif create keep ignore");
  run("RGB Color", "slices");

  run("RGB Color", "slices");

  run("RGB Color", "slices");

  run("RGB Color", "slices");

  run("RGB Color", "slices");

  run("Combine...", "stack1=CD22.tif stack2=TUBULIN.tif");
  saveAs("Tiff", "/Applications/ImageJ/Temp/Combo1.tif");

  run("Combine...", "stack1=GFP.tif stack2=DAPI.tif");
  saveAs("Tiff", "/Applications/ImageJ/Temp/Combo2.tif");

  run("Combine...", "stack1=Combo1.tif stack2=Combo2.tif combine");
  run("Combine...", "stack1=[Combined Stacks] stack2=Composite");
  saveAs("Tiff", filename2);
  run("Duplicate...", "duplicate range=6");
  saveAs("Jpeg", filename2);
  print(n++, filename, "->", filename2);

getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec);
saveAs("Text", dir2+"Log"+year+"-"+month+"-"+dayOfMonth);

//run("Startup Macros...");
1 Like

Dear @ronti69,

Just a few comments on your approach you might want to consider:
It seems that your output image type from your DeltaVision software is an RGB while you are working with fluorescence. To this end I would check, if your device can save the individual channels either as a composite image (where the channels are arranged as a stack or if you directly can export the individual channels in the original file format or at least as a tiff file.

Reason: If you save different channels as an RGB image right away you might get trouble because as @ctrueden already stated…

This means, if you afterwards split the channels you will only be able to get red, green and blue. If DeltaVision does not create these three channels with a “clean” LUT in the respective channels, so that e.g. the green LUT tends to also contain other colors or if you image something e.g. in cyan, yellow magenta,… and those colors are saved in the RGB type, you will not be able to recover the original channel information from those and mix up informations between channels.

I would always avoid JPG. This format uses lossy-compression to reduce the file size and comprises your data, which in the worst case looks like this:

For the contrast and brightness adjustments there are also a few things one should consider, when talking about figures for a publication:

  • Try to avoid oversaturation
  • Avoid completely black background
  • Be aware of changes in intensity ratios before and after the adjustment (comprises comparability of intensities)

The first two things you can easily check when you have a look at either the ►Analyze ►Histogram… or apply the ►Image ►Lookup Tables ►HiLo LUT on the grayscale image to check the saturation.

Since you tried to do that on an 16-bit (or in general on a grayscale image) you will always see this phenomenon because a grayscale image with a certain LUT assigned can have pixels only in the respective colors of this LUT. Thus, when the ►Image ►Stacks ►Tools ►Combine… function tries to merge two grayscale images it will always take over the LUT of the first one specified. This is solved (as you figured out) when first converting to RGB because then the respective colors are “baked” in. Like this you will also loose your 16-bit because RGB has only 8-bit per channel. This is not drastic for display reasons because computer screens display things only in an 8-bit range (256 intensity values per channel) anyway. In contrast, for an analysis this would be a deleterious change (so, never analyze intensities on an RGB image because you would loose bit-depth and mix the info from 3 channels, even the remaining 2 would be empty).

To create a figure which seems to be the purpose of your attempt you can try to run ►Image ►Color ►Merge Channels… (using the “create composite” checkbox would even now still keep your original bit depth). This will also still keep you channels separately accessible. Then apply the ►Image ►Stacks ►Make Montage… function. This enables you as well to specify separator lines between the images if desired (which is best done when the stack is already transfered to RGB first to be able having those lines e.g. in white, which you specify by adjusting the background color!)

For the final display you will need to create an RGB image before saving but up to that point you could still change the LUTs if desired.

If you want to display the individual channels next to each other and finally the merge image you could also create the merge image first, convert all images to RGB and combine them in a normal stack ►Image ►Stacks ►Images to Stack and thereafter run the montage function. Advantage of montages is that with e.g. the “Magic Montage” macroset from Jerome Mutterer or the adapted “Montage Tools” from the BioVoxxel Toolbox you can still reorganize the montage and semi-automatically label it.