Get "Direction (°)" from Directionality using an IJ1 Macro




I’m trying to write a macro that utilizes the Analyze > Directionality plugin. After running the plugin, a (what appears to be a) javascript window pops up and displays generated statistics from the analysis. I want to extract the value of the “Direction (°)” and assign that value to a variable in my macro.

I have tried using “getResult” but the table doesn’t seem to be a normal FIJI Result table (aside from its irregular name). So the solution here didn’t seem relevant to me.

Does anyone know how to do this?

Below is the code that I am working with. The unsuccessful things that I have tried are commented out.

run("Z Project...", "projection=[Average Intensity]");
run("Directionality", "method=[Local gradient orientation] nbins=90 histogram=-90");
//IJ.renameResults("Directionality analysis for AVG_0096 (using Local gradient orientation)","Results");
//getResult("Direction (°)",1)


The getResult() and IJ.renameResults() macro functions do not work with the table produced by the Directionality plugin because it is a JTable. There may be a way in a script or plugin to get a reference to this JTable (it’s not listed in the Window menu) and to access its cells.


As @Wayne said, the displayed table is not an ImageJ ResultsTable. You can resort to scripting as explained in the plugin documentation:

For example, you can use the following Groovy script from the script editor:

#@ ImagePlus imp
#@ ResultsTable rt

import fiji.analyze.directionality.Directionality_

d = new Directionality_()


result = d.getFitAnalysis()

mainDirection = Math.toDegrees(result[0][0])

rt.addValue("Main Direction", mainDirection)"Results")

If you save this script in a subfolder of Fiji’s scripts directory, e.g. as ./, and restart Fiji, you’ll then be able to run it from the menu and record its usage with the macro recorder, which will record something like:

run("Get Main Direction");

Subsequently you can get the value from the standard results table in the way you tried.


Wow thank you! Great to learn about this technique!


I came across this thread trying to batch the Directionality analysis. For anyone interested here is an implementation for batch processing and returning all 4 Directionality parameters in a results table:

Thanks to @imagejan for the code to get me started!