Batch Processing: Adjusting B&C and Using Channel tool


Attached are two different format (.Flex & .Tiff) of the same files generated by a high throughout screen and there are hundreds of those. I am a bit new to Image J and want to see whether I can do the following.

  1. To describe the contents of the image : the odd numbered channels (1,3,5) are the Green channels and the even numbered (2,4,6) are the corresponding Red channels (1-2 ; 3-4 ; 5-6)
  2. My objective is to set all Green channels MinAndMax as (10, 190) and a;; Red Channels MinandMax as (20.450).
  3. Then add “Green” to all green channels and “Red” to all red channels > Save them as coloured png images.

So far I have wrote the the following macro by looking into other examples to resolve problem 2. I have broken the “Flex” file into three different stacks containing the “Green” and it’s corresponding “Red” channel. Choose channel 1 and channel 2 separately. Assign the required MinAndMax and save them into three separate “tiff” files.

macro split_stack{ 
dir1 = getDirectory("Choose source directory"); 
list = getFileList(dir1); 
dir2 = getDirectory("Choose destination directory"); 
a = 1; 
 Dialog.addNumber("Number of images per stack",a);; 
a = Dialog.getNumber(); 
for (i=0; i<list.length; i++) { 
 getDimensions(width, height, channels, slices, frames); 
 title = File.nameWithoutExtension; 
 for (j=1; j< slices;j+=a){ 
  k = j+a-1;


  run("Make Substack...", "channels=1-"+channels+" slices="+j+"-"+k); 
  saveAs("tif", dir2+title+"-stack"+counter+".tiff"); 
showMessage("Macro is finished"); 

Firstly, I am not sure whether it had identified the correct MinAndMax for channel 1 as the output looks like it was using the values set for Channel 2. Secondly, how can I add the macro line to choose the correct colour for each channel?

Thanks in advance