Results table only giving last measurement in Headless

Hi I am trying to convert a macro I have working in GUI to headless. The overview of my project is that I open a directory do some processing and anlyze particles saving the ROIs to be applied to a corresponding Image from a second a directory. I then take measurements of the ROIs obtained from the first Image on the second and process through the directories. Based on a similar post "Results tables not found " in Headless Mode I have switched from using ROIs to Overlays in order to avoid the call to GUI. I am now getting the results of only the last measurement not all the complied ROIs as this proceeds through. I can see that the individual values are obtained by using a “print” command I can see them on the terminal window. The results I save somehow are only from the last ROI.

A condensed Version of code This is all within a loop that goes through all the files in a directory
//Open file from dir[0] and processes
run(“Analyze Particles…”, “size=4000-Infinity,show=Overlay”);
//Open file from dir[1] with corresponding string ID to Image being processed from dir[0] and threshold
}}//Close file loop

Because I can see the results on the terminal window I think that what is happening is that the GUI holds the "results in a table that you can extract is there a way to cumulatively add data to the same table in headless? I can find this which I think will help me… I think I shoudl eb able to create a results able and then add values but my coding skill level isn’t quite strong enough to translate this into my macro. I worte my macro in ImageJ language not JAVA and I’m not really sure how I can access these avaialble Java classes. Reading through the forum I can see where people use the commands IJ.renameResults(); for example but I get an error of an undefined identifier when I try to run the command without the IJ. in from and an unrecognized IJ function when I add it. "IJ.ResultsTable(“Phenotype.csv”); Can someone help?

The run(“Measure”) macro does not work with overlays, and it displays a “Results” window, not a good thing to do in headless mode. You can avoid these problems by using a script that loops through the overlay to do the measurements and measures using the Analyzer class directly. Here is a JavaScript example:

   img1 = IJ.openImage("");
   IJ.setAutoThreshold(img1, "Default");, "Analyze Particles...", "size=400 show=Overlay exclude");
   img2 = IJ.createImage("Untitled", "8-bit ramp", 256, 254, 1);
   overlay = img1.getOverlay();
   img2.setOverlay(overlay);"Set Measurements...", "area mean centroid decimal=3");
   rt = new ResultsTable();
   measurements = Analyzer.getMeasurements();
   for (i=0; i<overlay.size(); i++) {
      roi = overlay.get(i);
      analyzer = new Analyzer(img2, measurements, rt);
   path = IJ.getDir("temp")+"Results.xls";
   rt2 =;
1 Like

You can use macro code to measure all the ROIs in an overlay by using a loop, as in the following example. The example, however, opens the Results window, which will probably cause it to not work as expected in headless mode.

   run("Blobs (25K)");
   run("Analyze Particles...", "  show=Overlay");
   run("Blobs (25K)");
   for (i=0; i<Overlay.size; i++) {

Wayne I stumbled across this as I am looking for help with the post below. If I am looking to get %Area measure from a file (No overlay’s or ROIs needed) is there a better way to get this information than run(“Measure”); in headless mode. See post here Inconsistancy with code performance between GUI and Command Line possible issue with multiple reuslts?