Merge Channels Issue

channels
Tags: #<Tag:0x00007fd540718c58>

#1

I am running a macro program to merge 2 channels together. I am running
run(“Merge Channels…”, “c2=[” + list2[i] + “] c3=[” + list1[i] + “] keep”); and am getting correctly combined, merged images:

However, when I change to the channel color I want, I do not get the output I want. Instead of each image in the stack merging with the other stack, the images are interleaved and all in grey-scale.
run(“Merge Channels…”, “c2=[” + list2[i] + “] c6=[” + list1[i] + “] keep”);


The top image is data from one channel while the bottom image is from the other channel.

Am I changing the color correctly? I get the same code with the recorder in Fiji. All I have changed is c3 to c6.


#2

Dear @azmanr,

changing your macro code to

run("Merge Channels...", "c2=[" + list2[i] + "] c6=[" + list1[i] + "] keep ignore");

should create an image with the channels assigned to the colors you have set in the Merge channels… interface.

Best,
Stefan


#3

Hi @stelfrich

Thanks for your response. I am still getting the same issue even with your modification.
run(“Merge Channels…”, “c2=[” + list2[i] + “] c3=[” + list1[i] + “] keep ignore”); works perfectly, but if I change either c2 or c3 to another color I get the greyscale interleaved result shown in my last post. I have also tried
run(“Merge Channels…”, “c2=[” + list2[i] + “] c6=[” + list1[i] + “] create”); but I keep getting the same result.


#4

Could you provide one of your images so I can investigate on your data? I have no luck reproducing the issue with sample images. You can run the following macro with some scenarios that might trigger your issue but do actually work:

// Merges to composite hyperstack with the according LUTs
run("Confocal Series (2.2MB)");
run("Split Channels");
run("Grays");
selectWindow("C1-confocal-series.tif");
run("Grays");
run("Merge Channels...", "c1=C1-confocal-series.tif c6=C2-confocal-series.tif");

// Merges to RGB stack
run("Confocal Series (2.2MB)");
run("Split Channels");
run("Grays");
selectWindow("C1-confocal-series.tif");
run("Grays");
run("Merge Channels...", "c1=C1-confocal-series.tif c3=C2-confocal-series.tif");

// Merges to composite hyperstack with the according LUTs
run("Mitosis (26MB, 5D stack)");
run("Split Channels");
selectWindow("C1-mitosis.tif");
run("Merge Channels...", "c1=C1-mitosis.tif c6=C2-mitosis.tif ignore");

#5

I have been selecting GFP and MCherry directories with corresponding channel data in each separate folder. The directory containing both GFP and Mcherry folders is my output. If you try this code it should work for green and blue channel colors, but if you try changing c2 and c3 to anything else, you will get the greyscale, interleaved result.

Thanks,
Azman

macro "batch_merge_channels"{
    setBatchMode(true);
    file1 = getDirectory("Mcherry");
    list1 = getFileList(file1);
    n1 = lengthOf(list1);
 
    file2 = getDirectory("GFP");
    list2 = getFileList(file2); 
    file3 = getDirectory("Merge");
    //output
    list3 = getFileList(file3);
    n2 = lengthOf(list3);
    small = n1;
 

    for(i = 0; i < small; i++) {
      // for loop 
      name = list2[i];
      open(file1 + list1[i]);
      open(file2 + list2[i]);
   
run("Merge Channels...", "c2=[" + list2[i] + "] c3=[" + list1[i] + "] keep ignore");
      saveAs("tiff", file3 + name + "Merge");
   
    }
}


#6

I can’t see the files I posted, so I will post them again. I put each of these files in its own folder GFP and MCherry.

~Azman



#7

There are no previews of TIFF files in the forum. You have to right click and download them instead… the files are fine!


#8

I cannot reproduce this issue, @azmanr.

  • Which operating system are you on?
  • Where did you get ImageJ, i.e. is it ImageJ1/ImageJ2/Fiji?
  • If it is ImageJ2 or Fiji do you have SCIFIO enabled in Edit > Options > ImageJ?

#9

Hi @stelfrich,

Thanks for your response. I am using Fiji on OSX El Capitan. I have used bfconvert command line tools to generate tiff files that were distorted when I opened them back on Fiji, but were fine with other image software programs. In another chat forum, I got the suggestion to enable SCIFIO which fixed the problem. I think the issue has to do with this option; when I run my merge script with SCIFIO enabled, I get the greyscale output I posted above. When I run the script without SCIFIO enabled, I get the correct color, but I have the distorted issue I had with opening tiffs and my files are not merged correctly. Below is the output when SCIFIO is not enabled.

Image-Expt_17dpf_Fish2_WT_1xZoom1_MCherry.tiffMerge.tif.zip (6.9 MB)


#10

Dear @azmanr,

I cannot confirm this. The output for c2 and c6 is an image stack with a green and a magenta channel. Which version of Fiji are you running (click the status bar once to reveal that information)?

That’s actually a different “issue”. ImageJ1 is very particular about TIFF files and only “guarantees” to properly open TIFFs that have also been generated with ImageJ1. It seems that bfconvert generates TIFF files of such a form that you have to enable SCIFIO to be the default for opening images. You can, however, also trigger the loading of a file with SCIFIO via File > Import > Image without making it the default.


BfConvert Command Line Tool
#11

I am running Fiji 1.0 which I believe is the only version out.

Yes, I believe that the issue is with opening the files. You have suggested correctly that File> Import > Image as well as Bioformats opens the TIFF files correctly without SCIFIO.

I believe that modifying the code to open, using these methods, should fix the problem. But, implementing these image options can be a little tricky. Using the recorder, I got the code for File> Import> Image and Bioformats Import.

File> Import> Image

run("Image... ", "context=org.scijava.Context@75308740 datasetioservice=[io.scif.services.DefaultDatasetIOService [priority = 0.0]] logservice=[org.scijava.log.StderrLogService [priority = -100.0]] uiservice=[org.scijava.ui.DefaultUIService [priority = 0.0]] source=[/Users/labadmin/Desktop/From confocal/AS_Chi/17dpf/Image-Expt_17dpf_Fish6_chi_2xZoom1_left_GFP.tiff] x=0 y=0 w=0 h=0 mode=Auto");

Bioformats Import

run("Bio-Formats Importer", "open=[/Users/labadmin/Desktop/From confocal/AS_Chi/17dpf/Image-Expt_17dpf_Fish8_chi_2xZoom1_right_GFP.tiff] autoscale color_mode=Default rois_import=[ROI manager] split_channels view=Hyperstack stack_order=XYCZT");

I am trying to modify my script to change from open(file) to Bioformats Import, but that is tricky as I am not too sure on the syntax for Bioformats Importer using macro programming. I am not sure how to transfer the text name of the file in the loop to the bioformats function. This is what I have so far:

macro "batch_merge_channels"{
    setBatchMode(true);
    file1 = getDirectory("DAPI");
    //you can change the name of the inquiry to whatever wavelength you need, e.g. CY5
    list1 = getFileList(file1);
    //gets the list of files in the folder DAPI
    n1 = lengthOf(list1);
    //gets the number of files in folder DAPI, it should be the same as the number 
    //of files in folder GFP
    file2 = getDirectory("GFP");
    list2 = getFileList(file2); 
    file3 = getDirectory("Merge");
    //the output folder. When started first the number of files is 0
    list3 = getFileList(file3);
    n2 = lengthOf(list3);
    small = n1;
    //condition for for-loop

    for(i = 0; i < small; i++) {
      //i will always follow the aborted number of merges, you might not have the problem, 
      //but with small memory and a huge set of images it is useful
      name = list2[i];
      //Text input for Bioformats Importer
      open1=(file1 + list1[i]);
      open2=("file2 + list2[i]");

  // Bioformats Importer
run("Bio-Formats Importer", "open=["open1"] autoscale color_mode=Default rois_import=[ROI manager] split_channels view=Hyperstack stack_order=XYCZT");

run("Bio-Formats Importer", "open=["open2"] autoscale color_mode=Default rois_import=[ROI manager] split_channels view=Hyperstack stack_order=XYCZT");

run("Merge Channels...", "c2=[" + list2[i] + "] c3=[" + list1[i] + "] keep ignore");
      saveAs("tiff", file3 + name + "Merge");
   
    }
}

#12

What exactly does your status bar say? See the screenshot below for the relevant information:


Here you have to remove the quotation marks:

open1=(file1 + list1[i]);
print(open1); // prints something like "/home/azmanr/folder/file.tiff"
open2=("file2 + list2[i]");
print(open2); // prints exactly "file2 + list2[i]"

You have to insert a + to concatenate a string with the content of a variable:

run("Bio-Formats Importer", "open=["+open1+"] autoscale color_mode=Default rois_import=[ROI manager] split_channels view=Hyperstack stack_order=XYCZT");

#13

Looks like I have the same version as you. I have incorporated your syntax edits. I am not sure why you need to add print. I am getting an error though with bioformats importer that the file does not exist:

The macro programs are a little tricky to debug as it often won’t tell you the source of the error right away; I have been purposely making spelling errors to get the debug window open to track the variable list. It seems that I am unable to pass the file name correcly to open1 and open2.

Thanks,
Azman

macro "batch_merge_channels"{
    setBatchMode(true);
    file1 = getDirectory("DAPI");
    //you can change the name of the inquiry to whatever wavelength you need, e.g. CY5
    list1 = getFileList(file1);
    //gets the list of files in the folder DAPI
    n1 = lengthOf(list1);
    //gets the number of files in folder DAPI, it should be the same as the number 
    //of files in folder GFP
    file2 = getDirectory("GFP");
    list2 = getFileList(file2); 
    file3 = getDirectory("Merge");
    //the output folder. When started first the number of files is 0
    list3 = getFileList(file3);
    n2 = lengthOf(list3);
    small = n1;
    //condition for for-loop

    for(i = 0; i < small; i++) {
      //i will always follow the aborted number of merges, you might not have the problem, 
      //but with small memory and a huge set of images it is useful
      name = list2[i];
      //not to lose your track, though you can change it to anything else
     open1=(file1 + list1[i]);
print(open1); // prints something like "/home/azmanr/folder/file.tiff"
open2=("file2 + list2[i]");
print(open2); // prints exactly "file2 + list2[i]"

run("Bio-Formats Importer", "open=["+open1+"] autoscale color_mode=Default rois_import=[ROI manager] split_channels view=Hyperstack stack_order=XYCZT");

run("Bio-Formats Importer", "open=["+open2+"] autoscale color_mode=Default rois_import=[ROI manager] split_channels view=Hyperstack stack_order=XYCZT");


run("Merge Channels...", "c2=[" + list2[i] + "] c3=[" + list1[i] + "] keep ignore");
      saveAs("tiff", file3 + name + "Merge");
   
    }
}

BfConvert Command Line Tool
BfConvert Command Line Tool
#15

I think I experience the same or a similar issue and what I generally do is edit the header of the file by going to image properties (Image->Properties…), making sure the channels is 2 and the rest of the slice/frame is correct, also then making composite (Image->Color->Make Composite). You can script all of this, it might just work alone by making the image composite. I’ve never questioned this before, but maybe it is a bug.

run("Properties...", "channels= slices= frames= unit=unit pixel_width=1 pixel_height=1 voxel_depth=1.0000");
run("Make Composite", "display=Composite");	

To debug your macro you can open a text window (Plugins->New->Text Window…) and paste your macro code in. There is a debug menu there, which will allow you to do a few neat things listed [here] (http://imagejdocu.tudor.lu/doku.php?id=howto:working:how_to_use_the_macro_editor_s_debug_mode). Printing things to the log window at certain points in the script can be helpful to understand how far the script runs.


#16

Maybe @azmanr can give us an update if the issue is solved with the latest ImageJ daily build.

If not, it would be awesome to get some more information @7rebor to reproduce the issue!


#17

Sorry, I must have been mistaken, I can’t reproduce or find the problem anywhere in my data. What I may have been referring to was an easier way to go from interleaved stack to hyperstack by making the image composite (Image->Color->Make Composite), rather than going through stack to hyperstack menu (Image->Hyperstacks->Stack to Hyperstack…). I think this was the similar ‘problem’ that I mentioned, but not a bug!


#18

Oh, sorry about the misunderstanding! You are perfectly right that making a composite and then setting the lookup table should produce a similar result to what @azmanr is trying to achieve.


#19

Hi all,

Are you referring to the issue with importing tiff files into ImageJ from bfconvert tools? With SCIFIO enabled, I am able to import tiff files and change the file type for my need, but I am not able to import the tiff file correctly with FIle> Open.

~Azman


#20

I’m only referring to the merge problem.

Have you tried:

run("Make Composite", "display=Composite");

On your original problem when you get a grey interleaved result?