Posted by
TimFeinstein on
Jan 13, 2017; 1:52am
URL: http://imagej.273.s1.nabble.com/Macro-slowing-down-tp5017866p5017875.html
Hi folks,
Thanks to everyone who replied on and off list. People are no doubt right that OSX (and possibly Windows?) does not respond well to a Java macro that opens and closes and switches between windows thousands of times at a fever speed. I was able to streamline my macro dramatically when I found out that you can subtract one image from a whole stack:
http://imagej.1557.x6.nabble.com/Image-Calculator-Image-Slices-minus-Single-Image-td5015901.htmlI also gave up on creating a custom results table with a large 2D array of measurement results (sample ID x slice number). Instead I recorded one long results table and split out the individual stacks in Excel with some help from the INDIRECT() command.
The updated macro is below.
All the best,
Tim
Timothy Feinstein, Ph.D.
Research Scientist
University of Pittsburgh Department of Developmental Biology
----------------------------------------------------
//Analyze ciliary beat frequency using cropped movies
//Requires stable movies. Use the stackreg plugin on
//uncropped originals if you can see sample or camera motion.
setBatchMode(true);
if(isOpen("Results")) {
selectWindow("Results");
run("Close");
}
run("Clear Results");
setResult("Title", 0, 1);
run("Set Measurements...", "mean redirect=None decimal=5");
//Find the movies to analyze
files = getDirectory("Movies");
count = 0;
list = getFileList(files);
n = lengthOf(list);
//Set up the results table
//Duplicate out the 1st and nth frame of each movie
//and measure the average difference
for (i=0; i < n; i++) {
open(files+list[count]);
stack = getTitle();
fileName = list[i];
slices = nSlices();
if (slices < 310) {
selectWindow(stack);
run("Close");
count++;
} else {
run("Gaussian Blur 3D...", "x=1 y=1 z=1");
selectWindow(stack);
setSlice(1);
run("Duplicate...", "use");
first = getTitle();
imageCalculator("Difference create stack", stack, first);
diff = getTitle();
for (slice=1; slice<=300; slice++){
selectWindow(diff);
setSlice(slice+10);
run("Measure");
number = (nResults-1);
setResult("Title", number, stack);
}
selectWindow(stack);
run("Close");
selectWindow(diff);
run("Close");
selectWindow(first);
run("Close");
count++;
}
}
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html