I'm new to ImageJ, but am trying to learn more about writing macros.
I have images that end in "10Xred.tif", "10Xgreen.tif", "10Xblue," and "10Xlr.tif". I would like to process each color using different parameters.
The code that I have written only transfers all files from the input folder to the output folder, without processing them. I'm not sure where the problem is.
My apologies if this question might be tedious or unsuitable for forum purposes - any and all advice would be very much appreciated!
Thank you.
input = getDirectory("Input directory");
output = getDirectory("Output directory");
Dialog.create("File type");
Dialog.addString("File suffix: ", ".tif", 5);
Dialog.show();
suffix = Dialog.getString();
processFolder(input);
function processFolder(input) {
list = getFileList(input);
for (i = 0; i < list.length; i++) {
if(File.isDirectory(list[i]))
processFolder("" + input + list[i]);
if(endsWith(list[i], suffix))
processFile(input, output, list[i]);
}
}
function processFile(input, output, file) {
title = (File.getName(input));
if (indexOf(title, "10Xblue") >= 0) {
run("Channels Tool...");
run("Blue");
run("Subtract Background...", "rolling=50");
run("Multiply...", "value=1.2");
run("Set Scale...", "distance=1 known=0.65 pixel=1 unit=µm global");
run("Scale Bar...", "width=100 height=5 font=18 color=White background=None location=[Lower Right] bold overlay");
run("RGB Color");
run("Flatten"); }
else if (indexOf(title, "10Xred") >= 0) {
run("Channels Tool...");
run("Red");
run("Subtract Background...", "rolling=50");
run("Multiply...", "value=1.350");
run("Scale Bar...", "width=100 height=5 font=18 color=White background=None location=[Lower Right] bold overlay");
run("RGB Color");
run("Flatten");}
else if (indexOf(title, "10Xgreen") >= 0) {
run("Channels Tool...");
run("Green");
run("Subtract Background...", "rolling=50");
run("Multiply...", "value=1.250");
run("Scale Bar...", "width=100 height=5 font=18 color=White background=None location=[Lower Right] bold overlay");
run("RGB Color");
run("Flatten"); }
else if (indexOf(title, "10Xlr") >= 0) {
run("Channels Tool...");
run("Magenta");
run("Subtract Background...", "rolling=50");
run("Multiply...", "value=1.200");
run("Scale Bar...", "width=100 height=5 font=18 color=White background=None location=[Lower Right] bold overlay");
run("RGB Color");
run("Flatten");
}
print("Processing: " + input + file);
open(input + file);
print("Saving to: " + output);
saveAs("TIFF", output+file);
close();
}