Get Directionality Result e.g. “Goodness"

directionality
Tags: #<Tag:0x00007fd547f2d1d0>

#1

One way to analyze slope angles is Analyze==> Directionality (http://imagej.net/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

getDirectionalityResult(“Goodness”….

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.
    on
    https://github.com/fiji/Directionality/blob/master/src/main/java/fiji/analyze/directionality/Directionality_.java
    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.

#2

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.


#3

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?


#4

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.setImagePlus(WindowManager.getCurrentImage())
# dir.setMethod(fiji.analyze.directionality.Directionality_.AnalysisMethod.LOCAL_GRADIENT_ORIENTATION)
dir.setMethod(fiji.analyze.directionality.Directionality_.AnalysisMethod.FOURIER_COMPONENTS)
dir.setBinNumber(30)
dir.setBinStart(-60)
dir.setBuildOrientationMapFlag(True)

# Do calculation
dir.computeHistograms()
dir.fitHistograms()

# Display plot frame
plot_frame = dir.plotResults()
plot_frame.setVisible(True)

# Display fit analysis
data_frame = dir.displayFitAnalysis()
data_frame.setVisible(True) 

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

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

# Generate a color wheel
fiji.analyze.directionality.Directionality_.generateColorWheel().show()

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

goodness = dir.getGoodnessOfFit()

Does that help?


#5

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 New_.py at Mon Jul 17 12:11:46 EDT 2017
Traceback (most recent call last):
  File "New_.py", line 6, in <module>
NameError: name 'WindowManager' is not defined

	at org.python.core.Py.NameError(Py.java:284)
	at org.python.core.PyFrame.getname(PyFrame.java:257)
	at org.python.pycode._pyx2.f$0(New_.py:6)
	at org.python.pycode._pyx2.call_function(New_.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:167)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1386)
	at org.python.core.__builtin__.eval(__builtin__.java:497)
	at org.python.core.__builtin__.eval(__builtin__.java:501)
	at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:40)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
	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)

#6

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:
https://imagej.nih.gov/ij/developer/api/index.html


#7

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

#8

@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.


#9

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?