Re: Macro has slowed down dramatically when run in background
Posted by nelssara on
URL: http://imagej.273.s1.nabble.com/Macro-has-slowed-down-dramatically-when-run-in-background-tp5013659p5013661.html
Also, here is the code for the macro I am running. I have the batchmode as false, because otherwise it throws an error (and I am working with two monitors, so I can just leave imagej up and flashing away while I do other things...).
dir = getDirectory("Choose a Directory to PROCESS");
list = getFileList(dir);
dir2 = getDirectory("Choose a Directory for SAVING the PLA Image");
dir3 = getDirectory("Choose a Directory for SAVING the speckled PLA Image");
setBatchMode(false);
for (f=0; f<list.length; f++) {
path = dir+list[f];
print(path);
showProgress(f, list.length);
if (!endsWith(path,"/")) open(path);
if (nImages>=1) {
if (endsWith(path,"f")) {
t=getTitle();
s=lastIndexOf(t, '.');
ts=substring(t, 0,s);
ts2= ts +' PLA';
ts3= ts + ' speck';
ts4= ts + ' mask';
//Split channels
run("Split Channels");
selectWindow(t + " (blue)");
close();
selectWindow(t + " (green)");
close();
selectWindow(t + " (red)");
run("Subtract Background...", "rolling=50");
run("Duplicate...", " ");
selectWindow(t + " (red)-1");
run("Gray Morphology", "radius=3.5 type=circle operator=erode");
run("Gray Morphology", "radius=3.5 type=circle operator=dilate");
imageCalculator("Subtract create", t + " (red)", t + " (red)-1");
selectWindow("Result of " + t + " (red)");
rename(ts3);
saveAs("Tiff", dir3 + ts3);
run("Duplicate...", " ");
setAutoThreshold("Triangle dark");
setOption("BlackBackground", false);
run("Convert to Mask");
run("Make Binary");
run("Divide...", "value=255");
saveAs("Tiff", dir3 + ts4);
setMinAndMax(0, 1);
imageCalculator("multiply create", ts3 + ".tif", ts4 + ".tif");
selectWindow("Result of " + ts3 +".tif");
run("Brightness/Contrast...");
run("32-bit");
run("Divide...", "value=255");
run("Brightness/Contrast...");
setMinAndMax(0,1);
run("Set Measurements...", "integrated limit display redirect=None decimal=1");
run("Measure");
rename(ts3);
saveAs("Tiff", dir3 + ts3);
selectWindow(t + " (red)");
rename(ts2);
saveAs("Tiff", dir2 + ts2);
run("Close All");
}
}
}
selectWindow("Results");
saveAs("results", dir2 + "PLA Intensity values 2.xls");