Extract results from a non Result table

Tags: #<Tag:0x00007fa30437d990> #<Tag:0x00007fa30437d800>


Hi ,
I would need to extract as an array all the results from a table created by a Plugin (nnd)
As it not a standard results table, the usual following method do not work

for (i=0; i<nResults; i++){
  Array[i] = getResult("Column",i);

Any workaround?
Thanks again

Copy and Pasting Tracks
How Can I access the variables in tables in a macro

I assume your table has a different name than “Results”?
Maybe renaming your table into “Results” does the trick?



Good day Martin,

that’s what I would have recommended as well, but I wasn’t successful in doing it. Renaming works but accessing the data doesn’t. Don’t know why.




Good day,

here is a highly inelegant/clumsy way of getting the data from the custom results window “Nearest Neighbor Distances” into an array:

run( "Input/Output...", "jpeg=85 gif=-1 file=.txt copy_row" );
nme = "Nearest Neighbor Distances";
selectWindow( nme );
path = getDirectory( "temp" ) + nme + ".txt";
saveAs( "Results", path );
valArray = split( File.openAsString( path ), "\n" );
Array.show( valArray );

You may have to convert the valArray, that is a string array, to a float array.




In theory, you should be able to workaround this by temporarily renaming the standard Results table to some other name and renaming the “Nearest Neighbor Distances” table produced by the Nnd plugin to “Results”, using the IJ.renameResults() macro function (as @MartinH suggested).

But just the same as @Herbie, I wasn’t successful doing so, because the getResult() function seems to have problems with the unusual column header (---) produced by the Nnd plugin. Maybe @Wayne can comment on that.

Here’s what I tried but doesn’t work in this case:

IJ.renameResults("Results", "temp");
IJ.renameResults("Nearest Neighbor Distances", "Results");

distanceArray = newArray(nResults);
for (i=0; i<nResults; i++){
  distanceArray[i] = getResult("---",i);

IJ.renameResults("Results", "Nearest Neighbor Distances");
IJ.renameResults("temp", "Results");

print (distanceArray.length);

Now, you can of course work around it as @Herbie demonstrated by saving the data to disk and reading it back.

Another (and more elegant, IMHO) alternative is to use a script language like Groovy. Here’s a script that works (just run it from the script editor after choosing Language > Groovy in the menu):

import ij.WindowManager

windowTitle = "Nearest Neighbor Distances"

rt = WindowManager.getWindow(windowTitle).getTextPanel().getResultsTable()
distanceArray = rt.getColumn(0)

println distanceArray


Goofd day Jan,

I fear there is more than the “unusual column header (—)”, because after renaming the table to “Results”, the float values become integers. This appears rather strange to me and may turn out being a bug.




“the float values become integers”

Mea culpa, this behavior was due to a wrong setting of “Measurment”.
Sorry for the confusion.


Good day Alban,

finally I managed to access the data from an ImageJ macro without file operations.
Here is the code:

run( "Set Measurements...", "centroid redirect=None decimal=4" );
run( "Input/Output...", "jpeg=85 gif=-1 file=.txt save_column save_row" );
IJ.renameResults( "Results_AP" );
IJ.renameResults( "Nearest Neighbor Distances", "Results" )
valArray = split( String.paste, "\n" );
Array.show( valArray );

Again, you may have to convert the valArray, that is a string array, to a float array.




This latest ImageJ daily build (1.51s22) fixes a bug that caused the getResult() macro function to not work with tables created by plugins using the ResultsTable.setValue(column,row,value) method. The following macro demonstrates now to extract values from tables produced by the Nnd plugin.

   run("Blobs (25K)");
   run("Analyze Particles...", "display exclude clear include");
   run("Nnd ");
   IJ.renameResults("Nearest Neighbor Distances","Results");
   for (i=0; i<nResults; i++)
      print((i+1)+"  "+getResult("C1",i));


Hi unfortunately, something went wrong and this code doesn’t work anymore, it return NaN for each value of the Nnd. it is certainly related to the format of the results stored in C1 which are not real number. do you any thoughts?
Thanks again!


Good day Alban Favre,

Wayne’s demo macro still works fine here.




That’s strange, I am searching the bug for more than an hour and I’m stuck.Always the Nan results:


Here is a screen shot:

Good luck



please check if you have this updated version of ImageJ.

In FIJI, to do that you have to do: Help->Update ImageJ… and then select the “daily build” not the 1.51r
on that window you could also check which version you are running under list box.

I tried it now and with the 1.51r gets out “NaNs” with 1.51s34 (the current daily build) it gets out the correct data since it has the “C1” column instead of “—” heading

Hope it helps,
good day,
Emanuele Martini


Perfect, it was just that! thanks a lot



I don’t understand why it doesn’t work when it worked before.

If it really worked before, you must have installed ImageJ daily build (1.51s22) or newer.

Different computer??




Someone reupdated effectively imageJ to 1.51r version.


I updated ImageJ to 1.51s35 but obtained an exception when running Wayne’s macro.
Did I miss something?

(Fiji Is Just) ImageJ 2.0.0-rc-61/1.51s35; Java 1.8.0_66 [64-bit]; Windows 10 10.0; 28MB of 6110MB (<1%)
java.lang.IllegalArgumentException: Column not defined: 6
	at ij.measure.ResultsTable.getValueAsDouble(ResultsTable.java:354)
	at Nnd_.computennd(Nnd_.java:64)
	at Nnd_.run(Nnd_.java:43)
	at ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.java:265)
	at ij.plugin.filter.PlugInFilterRunner.<init>(PlugInFilterRunner.java:114)
	at ij.IJ.runUserPlugIn(IJ.java:223)
	at ij.IJ.runUserPlugIn(IJ.java:234)
	at ij.IJ.runPlugIn(IJ.java:185)
	at ij.Executer.runCommand(Executer.java:137)
	at ij.Executer.run(Executer.java:66)
	at ij.IJ.run(IJ.java:301)
	at ij.IJ.run(IJ.java:276)
	at ij.macro.Functions.doRun(Functions.java:604)
	at ij.macro.Functions.doFunction(Functions.java:96)
	at ij.macro.Interpreter.doStatement(Interpreter.java:247)
	at ij.macro.Interpreter.doStatements(Interpreter.java:233)
	at ij.macro.Interpreter.run(Interpreter.java:116)
	at ij.macro.Interpreter.run(Interpreter.java:87)
	at ij.macro.Interpreter.run(Interpreter.java:98)
	at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:161)
	at ij.IJ.runMacro(IJ.java:138)
	at ij.IJ.runMacro(IJ.java:127)
	at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1052)
	at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1048)
	at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:999)
	at net.imagej.legacy.IJ1Helper.runMacro(IJ1Helper.java:1048)
	at net.imagej.legacy.plugin.IJ1MacroEngine.eval(IJ1MacroEngine.java:136)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:159)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
	at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:237)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)


Dear @chin,
You have to punt “centroid” in the Set Measurements menu.

I think that is the problem,
have a nice day
Emanuele Martini


I tried Wayne’s macro, and it worked fine. I’m having trouble finding documentation for several types of macro commands like this one though.

First the commands that are sub to IJ…like IJ.renameResults()…Is there a doc that covers the syntax for these commands with a little description like the built in macro functions document?

Second the commands sub to Roi…like Roi.setStrokeWidth()…for instance, I’d like to control the arrow head size, but can’t find a command for it.

Please ID the paths to the docs that describe these,

Thanks in advance for your help.


Good day Ron,

a commented list of all ImageJ-macro calls is where you would expect it: