Sample image and/or code
TEST-1.tif (3.0 MB)
Background
Hello,
I am adapting a macro to do some analysis such as background subtraction, filtering but I want to. create a mask from one channel (channel3) and multiply to the stack and save.
I have not figure it out how to call the image that I am merging multiply with the channel 3.
Please, see figure attached and the code.
input = getDirectory("Choose an input directory");
output = getDirectory("Choose an output directory");
processFolder(input);
function processFolder(dir) {
list = getFileList(dir);
for (i=0; i<list.length; i++) {
if(endsWith(list[i], ".tif")) { //add the file ending for your images
processFile(dir, output, list[i]);
} else if(endsWith(list[i], "/") && !matches(output, ".*" + substring(list[i], 0, lengthOf(list[i])-1) + ".*")) {
//if the file encountered is a subfolder, go inside and run the whole process in the subfolder
processFolder(""+dir+list[i]);
} else {
//if the file encountered is not an image nor a folder just print the name in the log window
print(dir + list[i]);
}
}
}
function processFile(inputFolder, output, file) {
open(inputFolder + file);
title = getTitle();
run("Split Channels");
three = "C4-" +title;
two = "C3-" +title;
one = "C2-" + title;
run("Merge Channels...", "c1=["+one+"] c2=["+two+"] c3=["+three+"] create");
run("ROI Manager...");
//setTool("rectangle");
waitForUser("Draw ROI, then hit OK");
if (selectionType==-1)
exit("This macro requires an area selection");
for (j=1; j<=nSlices; j++) { // loop through slices in image
setSlice(j);
getStatistics(area, mean);
run("Select None");
run("Subtract...", "value="+mean);
run("Median...", "radius=1.0 stack");
run("Restore Selection");
}
saveAs("tiff", output + file);
close(file);
run("Close All");
}
Analysis goals
I want to be able to use this pieces of instruction that I have in another macro but it is written in a way that I am not able to combine with the code above.
selectWindow("C3-" + list[ i ]);
run("Duplicate...", "title=bodiemask");
setAutoThreshold("Li dark no-reset");
run("Threshold...");
call("ij.plugin.frame.ThresholdAdjuster.setMode", "Over/Under");
waitForUser("Imagen "+n+" de "+length,"Apply Threshold y click OK");
run("Subtract...", "value=254");
saveAs("Tiff", path + "output/Bodiemask" + i);
imageCalculator("multiply create 32-bit", "Bodiemask", "HERE I WANT TO PUT MY MERGE3CHANNEL+i+".tif")
Challenge
Can someone give me some guide to continue improving this macro, please?
I would really appreciate.
Thanks in advance