Posted by
Javier MazarÃo on
Feb 02, 2017; 4:46pm
URL: http://imagej.273.s1.nabble.com/help-with-Batch-Merge-of-2-channel-image-sequence-tp5001242p5017999.html
Hi,
I know this a very old post but in case someone comes across this message, as I did, here is the modification of the "Batch RGB Merge" code (from
https://imagej.nih.gov/ij/macros/Batch_RGB_Merge.txt) that I made a while ago. This is to merge blue and green images. I've also made other versions to merge blue and red, red and green, other combinations of three colors different to the original code, 4 channels and 5 channels. Feel free to contact me if you think you could use any of them.
I hope this is helpful
// "Batch RGB Merge blue and green"
// Opens multiple sets of two separate color channels as
// an RGB stack or converts them to RGB images. File names
// ending in "verde" and "azul" are assumed to be green and
// blue channels respectively, but this can be changed in
// the dialog box.
// A sample image set, courtesy of Mikael Bjorklund, is available at:
//
http://rsb.info.nih.gov/ij/macros/images/DrosophilaCells.zip// It consists of three images of Drosophila S2 cells,
// each with three channels (d0=blue, d1=red and d2=green
// as indicated by the end of the filename. The staining is
// standard Hoechst, phalloidin, tubulin.
Dialog.create("RGB Batch Convert");
//Dialog.addString("Red Suffix:", " rojo");
Dialog.addString("Green Suffix:", " verde");
Dialog.addString("Blue Suffix:", " azul");
//Dialog.addString("Gray Suffix:", " gris");
Dialog.addCheckbox("Open as Stack", false);
Dialog.show();
//redSuffix = Dialog.getString() + ".";
greenSuffix = Dialog.getString() + ".";
blueSuffix = Dialog.getString() + ".";
//graySuffix = Dialog.getString() + ".";
openAsStack = Dialog.getCheckbox();
if (openAsStack)
openImagesAsStack();
else
batchConvert();
exit;
function openImagesAsStack() {
dir = getDirectory("Choose Source Directory ");
list = getFileList(dir);
setBatchMode(true);
n = list.length;
if ((n%2)!=0)
exit("The number of files must be a multiple of 2");
stack = 0;
first = 0;
for (i=0; i<n/2; i++) {
showProgress(i+1, n/2);
green="?"; blue="?";
for (j=first; j<first+2; j++) {
//if (indexOf(list[j], redSuffix)!=-1)
//red = list[j];
if (indexOf(list[j], greenSuffix)!=-1)
green = list[j];
if (indexOf(list[j], blueSuffix)!=-1)
blue = list[j];
//if (indexOf(list[j], graySuffix)!=-1)
//gray = list[j];
}
//open(dir+red);
open(dir+green);
open(dir+blue);
//open(dir+gray);
//run("Merge Channels...", "c1=["+red+"] c2=["+green+"] c3=["+blue+"] c4=["+gray+"]");
run("Merge Channels...", "c2=["+green+"] c3=["+blue+"]");
//close();
width=getWidth; height=getHeight;
run("Copy");
close();
if (stack==0) {
newImage("RGB Stack", "RGB Black", width, height, n/2);
stack = getImageID;
}
selectImage(stack);
setSlice(i+1);
run("Paste");
//index = indexOf(red, redSuffix);
//name = substring(red, 0, index);
index = indexOf(green, greenSuffix);
name = substring(green, 0, index);
setMetadata(name);
first += 2;
}
setSlice(1);
run("Select None");
setBatchMode(false);
}
function batchConvert() {
dir1 = getDirectory("Choose Source Directory ");
dir2 = getDirectory("Choose Destination Directory ");
list = getFileList(dir1);
setBatchMode(true);
n = list.length;
if ((n%2)!=0)
exit("The number of files must be a multiple of 2");
stack = 0;
first = 0;
for (i=0; i<n/2; i++) {
showProgress(i+1, n/2);
green="?"; blue="?";
for (j=first; j<first+2; j++) {
//if (indexOf(list[j], redSuffix)!=-1)
//red = list[j];
if (indexOf(list[j], greenSuffix)!=-1)
green = list[j];
if (indexOf(list[j], blueSuffix)!=-1)
blue = list[j];
//if (indexOf(list[j], graySuffix)!=-1)
//gray = list[j];
}
//open(dir1 +red);
open(dir1 +green);
open(dir1 +blue);
//open(dir1 +gray);
//run("Merge Channels...", "c1=["+red+"] c2=["+green+"] c3=["+blue+"] c4=["+gray+"]");
run("Merge Channels...", "c2=["+green+"] c3=["+blue+"]");
//close();
//index = indexOf(red, redSuffix);
//name = substring(red, 0, index);
index = indexOf(green, greenSuffix);
name = substring(green, 0, index);
saveAs("tiff", dir2+name);
first += 2;
run("Close All");
}
}
<quote author="Jeremy Florman">
I have a large data set of two channel tiff images that I would like to merge. I've been trying to find/write a plugin to facilitate this and the batchRGBmerge macro seems to be just what I'm looking for but I am running into trouble due to the fact that my images are 2-channel rather than 3-channel. My filenames have the suffix w1.tif (blue) and w2.tif (green) but I've been unable to get the batchRGB merge to recognize these suffixes or run with multiples of 2. If anyone could help me here or suggest an existing plugin/macro to accomplish this it would be greatly appreciated.
Jeremy Florman
Neurobiology Department
Umass Medical School
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html