Posted by
Nathaniel Ryckman on
May 19, 2011; 6:24pm
URL: http://imagej.273.s1.nabble.com/need-advice-on-batch-macros-tp3684525p3684528.html
olao4 wrote
Thanks for a fast reply!
I still have a problem though.
It says that some variable is undefined, I guess it means curDir, even after I added the two lines you posted later...
I didn't give you the EXACT code. I only gave you some starting points. Here, I just wrote the following code for you, but I didn't test it out:
// Get image to do subtraction
userImg = File.openDialog("Select Specified File")
open(userImg);
imgName = File.getName(userImg);
// Get file list
head = getDirectory("Choose a directory containing raw image sets.");
children = getFileList(head);
// Set batch mode to true
setBatchMode(true);
// Process each image
for(i = 0; i < children.length; i++)
{
// Open 2nd image
curChild = head + children[i];
open(curChild);
// Subtraction
imageCalculator("Subtract create", imgName, children[i]);
// Invert result
selectWindow("Result of " + imgName);
run("Invert");
// Save result
selectWindow("Result of " + imgName);
saveAs("Tiff", head + "Result_" + imgName);
close();
// Close 2nd image
selectWindow(children[i]);
close();
}
// Close 1st image
selectWindow(imgName);
close();
A few things to note:
1) I didn't know if you are trying to subtract the 1st image from the 2nd or the 2nd from the first.
2) If you want to continue using Macros, you will unfortunately need to learn a little programming. Herre are some resources:
http://rsb.info.nih.gov/ij/developer/macro/macros.htmlhttp://rsbweb.nih.gov/ij/developer/macro/functions.htmlStart imageJ and then use Plugins->Macros->Record...