Results table only giving last measurement in Headless


#1

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”);
Overlay.copy;
//Open file from dir[1] with corresponding string ID to Image being processed from dir[0] and threshold
Overlay.paste
run(“Measure”);
}}//Close file loop
saveAs((“Results”,dir[2]+“Phenotype.csv”);

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 http://javadoc.imagej.net/ImageJ1/ij/measure/ResultsTable.html 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?


#2

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("http://wsr.imagej.net/images/blobs.gif");
   IJ.setAutoThreshold(img1, "Default");
   IJ.run(img1, "Analyze Particles...", "size=400 show=Overlay exclude");
   img2 = IJ.createImage("Untitled", "8-bit ramp", 256, 254, 1);
   overlay = img1.getOverlay();
   img2.setOverlay(overlay);
   IJ.run("Set Measurements...", "area mean centroid decimal=3");
   rt = new ResultsTable();
   measurements = Analyzer.getMeasurements();
   for (i=0; i<overlay.size(); i++) {
      roi = overlay.get(i);
      img2.setRoi(roi);
      analyzer = new Analyzer(img2, measurements, rt);
      analyzer.measure();
   }
   path = IJ.getDir("temp")+"Results.xls";
   rt.saveAs(path);
   rt2 = ResultsTable.open(path);
   //rt2.show("Results");

#3

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.

   setBatchMode(true);
   run("Blobs (25K)");
   setAutoThreshold("Default");
   run("Analyze Particles...", "  show=Overlay");
   Overlay.copy;
   close;
   run("Blobs (25K)");
   Overlay.paste();
   for (i=0; i<Overlay.size; i++) {
      Overlay.activateSelection(i);
      run("Measure");
   }

#4

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?