Novice with an exception error in macro

Hello all,

I am running the following macro in batch mode and getting an exception that I can’t even begin to understand. It cycles through the first image and makes the measurement but doesn’t open the next image in the “input” folder. My goal is to be able to watch the image processing as it progresses but have each image set close after the analysis so that I don’t have hundreds of image windows open at the end. Thanks in advance for your suggestions.

T = getTitle();
run(“Split Channels”);
selectWindow(T+" (blue)");
run(“Subtract Background…”, “rolling=50”);
waitForUser(“select area then click edit–>selection–>create selection then click ok”);
selectWindow(T+" (red)");
run(“Subtract Background…”, “rolling=30”);
setAutoThreshold(“Default dark”);
setThreshold(31, 217);
run(“Restore Selection”);
run(“Analyze Particles…”, “size=50-100 pixel summarize”);
run(“Close All”);

ImageJ 1.48v; Java 1.6.0_65 [64-bit]; Mac OS X 10.12.3; 142MB of 658MB (21%)

at ij.process.ColorProcessor.(
at ij.ImagePlus.setupProcessor(
at ij.ImagePlus.getFileInfo(
at ij.IJ.saveAsTiff(
at ij.IJ.saveAs(
at ij.plugin.BatchProcessor.processFolder(
at ij.IJ.runPlugIn(
at ij.Executer.runCommand(


Do you have other files in the input folder other than images? You should only have images in that folder which imagej should analyze.


The only other thing in the folder with the images is an output folder for the post-processing file that is generated.

I am not able to reliably reproduce this exception but I suspect it occurs because the macro closes the image which the Process>Batch>Macro command is trying to save. You can avoid this problem by leaving the “Output…” field blank. It’s probably better, however, to avoid the Process>Batch>Macro command, which is not designed to work with displayed images or with the waitForUser() function. Instead, use a simple macro like the following that iterates through all the images in a folder.

  dir = getDirectory("Choose Source Directory ");
  list = getFileList(dir);
  for (i=0; i<list.length; i++) {
     T = getTitle(); 
     run("Split Channels"); 
     selectWindow(T+" (blue)");
     run("Subtract Background...", "rolling=50");
     waitForUser("select area then click edit>selection>create selection then click ok");
     selectWindow(T+" (red)");
     run("Subtract Background...", "rolling=30");
     setAutoThreshold("Default dark");
     setThreshold(31, 217);
     run("Restore Selection");
     run("Analyze Particles...", "size=50-100 pixel summarize");
     run("Close All");