|
I have a large number of .tiff images I wish to merge. They comprise of sets of two images, one in brightfield and the other in fluorescent/red. The file names are as follows:
Exp.SS.4.4.170 - DF1 - MSTN HDR donor candidate 1 - 2 ul Lipofectamine 2000 - 15x - Field 1 - Brightfield - 2012-03-20.tif
Exp.SS.4.4.170 - DF1 - MSTN HDR donor candidate 1 - 2 ul Lipofectamine 2000 - 15x - Field 1 - UV red - 2012-03-20.tif
Exp.SS.4.4.170 - DF1 - MSTN HDR donor candidate 1 - 3 ul Lipofectamine 2000 - 15x - Field 2 - Brightfield - 2012-03-20.tif
Exp.SS.4.4.170 - DF1 - MSTN HDR donor candidate 1 - 3 ul Lipofectamine 2000 - 15x - Field 2 - UV red - 2012-03-20.tif
Exp.SS.4.4.170 - DF1 - MSTN HDR donor candidate 1 - 4 ul Lipofectamine 2000 - 15x - Field 3 - Brightfield - 2012-03-20.tif
Exp.SS.4.4.170 - DF1 - MSTN HDR donor candidate 1 - 4 ul Lipofectamine 2000 - 15x - Field 3 - UV red - 2012-03-20.tif
Exp.SS.4.4.170 - DF1 - MSTN HDR donor candidate 1 - 5 ul Lipofectamine 2000 - 15x - Field 1 - Brightfield - 2012-03-20.tif
Exp.SS.4.4.170 - DF1 - MSTN HDR donor candidate 1 - 5 ul Lipofectamine 2000 - 15x - Field 1 - UV red - 2012-03-20.tif
Exp.SS.4.4.170 - DF1 - MSTN HDR donor candidate 1 - 2 ul Lipofectamine 2000 - 15x - Field 2 - Brightfield - 2012-03-20.tif
I would like the output names to be derived from the input names as follows:
Input file names:
Exp.SS.4.4.170 - DF1 - MSTN HDR donor candidate 1 - 2 ul Lipofectamine 2000 - 15x - Field 1 - Brightfield - 2012-03-20.tif
Exp.SS.4.4.170 - DF1 - MSTN HDR donor candidate 1 - 2 ul Lipofectamine 2000 - 15x - Field 1 - UV red - 2012-03-20.tif
Output file names:
Exp.SS.4.4.170 - DF1 - MSTN HDR donor candidate 1 - 2 ul Lipofectamine 2000 - 15x - Field 1 - Merged - 2012-03-20.tif
So far, I've scraped together a few pieces of macro code which appear relevant to this endeavour.
//Need a way to open the images.
//I don't know what this does. Copied and pasted it from somewhere
for (i=0; i<filename.length; i++) {
if(endsWith(filename[i], ".tif")) {
open(path+filename[i]);
//Prepares red image
selectWindow(title+"+red+");
run("8-bit");
setMinAndMax("49, 205");
run("Apply LUT");
//Prepares brightfield image
selectWindow(title+"+Brightfield+");
run("8-bit");
//Merge the images
run("Merge Channels...", "red=["+red+"] green=*none* blue=*none* gray=["+Brightfield+"] keep);
//Need to find a way to save the images with the file name kept the same except 'Merged'.
//Need to find a way to make the macro cycle through all the images in the folder and then stop when it has merged the last two images.
|