Search code examples
imagej

How to create empty Result table after run("Analyze particles...") imageJ


I'm trying to create an empty Result table table in ImageJ.

I'd like to be able to use the analyze particles:

run("Analyze Particles...", "size=8-100 circularity=0.00-1.00 show=Nothing display clear include record");

but then, if the count of detected particles is zero, I'd like to get a Result table with all the columns that I'd usually get such as Label, Area, Mean etc.. (and just fill them out with zeros).

The reason is, that I'd like to include results from images without any counts as 'zero particles'. I'm running in batch mode to analyze particles on multiple images and extract some simple statistics in another, custom table that I write to a file. I've tried to use

setResult()

, but it doesn't seem to work when no particles are counted. The reason I want to use the Result table is that I use

getResult()

to retrieve the values that I put into my custom output table...

I have looked through the documentation and different forums, but cannot find a solution.

I'll be looking forward to any help or suggestions.


Solution

    • When running Analyze Particles... with the Summarize option checked, you get a summary table that contains a line even if no particles were found.

    • If you want to record a new line to the main Results table, you should use setResult("Label", row, string) like follows to add a new line with the label set to the image title, and all columns set to 0:

      currentNResults = nResults;
      run("Analyze Particles...", "display summarize");
      if (nResults == currentNResults) {  // if Analyze Particles did not find any particles
          setResult("Label", nResults, getTitle());
      }
      
    • If you want to use a customized results table different from the standard ImageJ results table (the one saying Results in the window title), you should better resort to using JavaScript scripting, where you have direct access to the ij.measure.ResultsTable class, e.g.:

      rt = new ResultsTable();
      rt.incrementCounter();
      rt.addLabel("My Label");
      rt.addValue("My parameter", 1.234);
      rt.show("My own results table");
      

    Hope that helps.