Get Directionality Result e.g. “Goodness"

Tags: #<Tag:0x00007fd547f2d1d0>


One way to analyze slope angles is Analyze==> Directionality ( ) It provides Amount and Goodness as an output that could be very helpful in outlier elimination. Additionally the results in the Directionality result table seem difficult to access from the scripting language. I would want to put those results into an array.

roiManager("Select", 1);
run("Directionality", "method=[Fourier components] nbins=90 histogram=-90");

After Analyze>Measure I can pick out the result with

angleA = getResult("Angle", 0);
angArray = Array.concat(angArray, angleA);

Is there a similar way to


The only way to get to the results given on the webpage is:

  1. Save the Directionality Results window contents to a spreadsheet by copy pasting.
    The macro recorder does not record this cut and paste action and it would be very difficult to get that CSV file concatenated with an array.
    I see it should be possible to run form a script.
    For slopes where the goodness is very close to 1 it may be desirable to obtain more than two decimals, so if I get access to the raw data I would want more precision.


Hi @stmfiji

The ‘goodness’ is only the goodness of fit for a gaussian fit on the directionality histogram.
I am not at all if it is what you need for your slop analysis.


Thank you very much @tinevez, am aware that the goodness is from fitting the Gaussian. But I am still sure the Goodness would be very helpful especially when combining it with the min Feret of the individual objects.
Do you see any way to get to this data from within an IJ1Macro script?


Not from an IJ1 Macro, but with any other supported scripting language. Did you have a look at the Javadoc? From there:

It is also possible to run the plugin non-interactively from another class, or even in a script. For instance in Python:

import fiji.analyze.directionality.Directionality_
# Instantiate plugin
dir = fiji.analyze.directionality.Directionality_()
# Set fields and settings
# dir.setMethod(fiji.analyze.directionality.Directionality_.AnalysisMethod.LOCAL_GRADIENT_ORIENTATION)

# Do calculation

# Display plot frame
plot_frame = dir.plotResults()

# Display fit analysis
data_frame = dir.displayFitAnalysis()

# Display results table
table = dir.displayResultsTable()"Directionality histograms")

# Display orientation map
stack = dir.getOrientationMap()
ImagePlus("Orientation map", stack).show()

# Generate a color wheel

So after running, you can get the goodness of fit using:

goodness = dir.getGoodnessOfFit()

Does that help?


Thank you very much, but I would need more detailed advice.

I copied your code into the script editor and then set the language to Python.
I have an image open and when I run Directionality from the menu it works.
When I run the python script, I get the error at the bottom of this post. I must be missing a critical step.

Thanks also for the link to the JAVADOC. At this time I am still trying to get the ECLIPSE to work and at this point it seems to have insurmountable problems.

Started at Mon Jul 17 12:11:46 EDT 2017
Traceback (most recent call last):
  File "", line 6, in <module>
NameError: name 'WindowManager' is not defined

	at org.python.core.Py.NameError(
	at org.python.core.PyFrame.getname(
	at org.python.pycode._pyx2.f$0(
	at org.python.pycode._pyx2.call_function(
	at org.python.core.Py.runCode(
	at org.python.core.__builtin__.eval(
	at org.python.core.__builtin__.eval(
	at org.python.util.PythonInterpreter.eval(
	at org.python.jsr223.PyScriptEngine.eval(
	at org.python.jsr223.PyScriptEngine.eval(
	at javax.script.AbstractScriptEngine.eval(
	at org.scijava.thread.DefaultThreadService$
	at java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.util.concurrent.ThreadPoolExecutor$


Hi @stmfiji

You have to add import lines for all the classes you want to use in the script. Here the error points to the WindowManager class so you have to add

import ij.WindowManager

to the beginning of your script.

You can find the list of ImageJ classes and their import path there:


I had copied the above code example verbatim from the Directionality_ javadoc, and as @tinevez pointed out, it is missing a few required imports. In summary, adding the following lines at the beginning of the script should work:

from ij import WindowManager
from ij import ImagePlus


@imagejan I think that I made these scripts at the time where we used @albertcardona and @dscho first iterations of the script editor, that was automatically importing all IJ classes at startup.

All my scripts from this era probably have the same problems.


This is very nice
After adding the two lines

from ij import WindowManager
from ij import ImagePlus

at the beginning and

goodness = dir.getGoodnessOfFit()
print (goodness)

at the end.
I get the result

array('d', [0.994318341926021])

in the output window underneath the python script

Is there any way to call the Python script from my IJ1Macro and have the goodness returned or can scripts in different languages share variables?