public class Directionality_ extends Object implements ij.plugin.PlugIn
Angles are reported in their common mathematical sense. That is: 0º is the East direction, and the orientation is counterclockwise.
It is possible to limit the analysis to a range of angles lower than the default 180 degrees.
The highest peak is fitted by a Gaussian function, taking into account the periodic nature of the histogram. The 'Direction (º)' column reports the center of the gaussian. The 'Dispersion (º)' column reports the standard deviation of the gaussian. The 'Amount' column is the sum of the histogram from the center of the peak to two standard deviation away, divided by the total sum of the histogram. The real histogram values are used for the summation, not the gaussian fit. The 'Goodness' column reports the goodness of the fit; 1 is good, 0 is bad.
A study made on artificial images reveal that the 'Amount' value as calculated here underestimates the real proportion of structures with the preferred orientation.
This plugin chops the image into square pieces, and computes their Fourier power spectra. The later are analyzed in polar coordinates, and the power is measured for each angle using the spatial filters proposed in [1].
In the later case, the image is filtered using the Fourier filters described above, and transformed back using inverse Fourier transform. For each pixel, the direction retained is the one that has the strongest intensity when filtered in this orientation.
To generate the orientation map image, a HSB image is made by taking
PlugIn
.
String arguments can be passed to it, using the run(String)
method.
For instance:
ImagePlus imp = IJ.openImage( "./TwoLines.tif" ); imp.show(); Directionality_ da = new Directionality_(); da.run( "nbins=60, start=-90, end=90, method=gradient" );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) # Alternatively set a range # dir.setBinRange(-60,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(dir.getBinStart(), dir.getBinEnd()).show()
A discussion with A. Leroy and another one with J. Schindelin are greatly acknowledged.
Modifier and Type | Class and Description |
---|---|
static class |
Directionality_.AnalysisMethod |
Modifier and Type | Field and Description |
---|---|
protected double[] |
bins
The bin centers, in radians.
|
protected boolean |
debug
If true, will display FFTs and filters.
|
protected ij.ImageStack |
filters
Fourier filters are stored as a stack
|
protected String |
fit_string
Store a String representing the fitting function.
|
protected double[] |
goodness_of_fit
Store goodness of fit results when fit method is called.
|
protected int |
height |
protected ArrayList<double[]> |
histograms
The directionality histogram, one array per processor (3 in the case of a
ColorProcessor).
|
protected ij.ImagePlus |
imp
The ImagePlus this plugin operates on.
|
protected int |
long_side |
protected int |
nbins
The number of bins to create.
|
protected int |
npadx |
protected int |
npady |
protected int |
pad_size |
protected ArrayList<double[]> |
params_from_fit
Store fit results when fit method is called.
|
protected ij.process.FloatProcessor |
r
Polar coordinates, stored as a FloatProcessor.
|
protected int |
small_side |
protected int |
step |
protected ij.process.FloatProcessor |
theta
Polar coordinates, stored as a FloatProcessor.
|
protected int |
width |
protected ij.process.FloatProcessor |
window
Polar coordinates, stored as a FloatProcessor.
|
Constructor and Description |
---|
Directionality_() |
Modifier and Type | Method and Description |
---|---|
protected static void |
addColorMouseListener(ImageCanvas canvas,
double angle_start,
double angle_end) |
void |
computeHistograms()
This method runs the analysis on all slices, and store resulting
histograms in the histogram fields.
|
protected static LookupPaintScale |
createLUT(int ncol)
Generate a bluish to greenish to redish LUT for the display of
histograms.
|
JFrame |
displayFitAnalysis()
This method displays the fit analysis results in a
JTable . |
protected static ij.process.FloatProcessor |
displayLog(ij.process.FloatProcessor ip)
This utility method returns a FloatProcessor with the log10 of each pixel
in the
FloatProcessor given in argument. |
ij.measure.ResultsTable |
displayResultsTable()
This method generates a
ResultsTable containing the histogram
data for display in ImageJ. |
void |
fitHistograms()
This method tries to fit a gaussian to the highest peak of each
directionality histogram, and store fit results in the
params_from_fit field. |
static ij.ImagePlus |
generateColorWheel(double angle_start,
double angle_end) |
double |
getBinEnd()
Returns the current value for angle bin end, in degrees.
|
int |
getBinNumber()
Returns the current number of bins for this instance.
|
double[] |
getBins()
Returns the center of the bins for the directionality histograms.
|
double |
getBinStart()
Returns the current value for angle bin start, in degrees.
|
protected static double[] |
getBlackmanPeriodicWindow1D(int n)
This utility generates a periodic Blackman window over n points.
|
protected static ij.process.FloatProcessor |
getBlackmanProcessor(int nx,
int ny)
Generate a 2D Blackman window used in this plugin before computing FFT,
so as to avoid the cross artifact at x=0 and y=0.
|
ArrayList<double[]> |
getFitAnalysis()
Return the result of analyzing the gaussian fit of the peak.
|
ArrayList<double[]> |
getFitParameters()
Returns the parameters of the gaussian fit of the main peak in histogram.
|
double[] |
getGoodnessOfFit()
Returns the goodness of fit for the gaussian fit; 1 is good, 0 is bad.
|
ArrayList<double[]> |
getHistograms()
Returns the directionality histograms as an ArrayList of double[], one
array per slice.
|
ij.ImagePlus |
getImagePlus()
Gets the image analyzed.
|
Directionality_.AnalysisMethod |
getMethod()
Returns the analysis method used by this instance.
|
ij.ImageStack |
getOrientationMap()
Returns the orientation map as an
ImageStack , one slice per slice
in the source image. |
static void |
main(String[] args) |
protected static ij.process.FloatProcessor |
makeRMatrix(int nx,
int ny)
Generate a 2D matrix of the radius polar coordinates, centered in the
middle of the image.
|
protected static ij.process.FloatProcessor |
makeThetaMatrix(int nx,
int ny)
Generate a 2D matrix of the angle polar coordinates, centered in the
middle of the image.
|
protected static String |
parseArgumentString(String argument_string,
String command_str)
Utility method to analyze the content of the argument string passed by
ImageJ to this plugin using the
setup(String, ImagePlus) method. |
JFrame |
plotResults()
This method is called to draw the histograms resulting from image
analysis.
|
protected static double[] |
prepareBins(int n,
double first,
double last)
Generate a bin array of angle in radians, from -pi/2 to pi/2.
|
void |
run(String arg)
Called when this plugin is launched from ImageJ.
|
void |
setBinNumber(int nbins)
Sets the desired number of bins.
|
void |
setBinRange(double bin_start,
double bin_end)
Sets the desired end for the angle bins, in degrees.
|
void |
setBinStart(double bin_start)
Sets the desired start for the angle bins, in degrees.
|
void |
setBuildOrientationMapFlag(boolean flag)
Sets the build orientation map flag
|
void |
setDebugFlag(boolean flag)
Sets the debug flag.
|
void |
setImagePlus(ij.ImagePlus imp)
Sets the image for analysis.
|
void |
setMethod(Directionality_.AnalysisMethod method)
Sets the desired method for analysis.
|
protected ij.ImagePlus imp
protected boolean debug
protected int nbins
protected ij.ImageStack filters
protected ij.process.FloatProcessor window
protected ij.process.FloatProcessor r
protected ij.process.FloatProcessor theta
protected int width
protected int height
protected int small_side
protected int long_side
protected int npady
protected int npadx
protected int step
protected int pad_size
protected double[] bins
protected ArrayList<double[]> histograms
protected ArrayList<double[]> params_from_fit
protected double[] goodness_of_fit
protected String fit_string
public void run(String arg)
computeHistograms()
method, which computes the
histograms
fitHistograms()
method, which fits the histograms
If the method is called with String arguments, fields are set according to it, and no dialog are displayed (macro recordable).
run
in interface ij.plugin.PlugIn
arg
- the string argument, for instance "nbins=90, start=-90,
end=90, method=gradient"public void computeHistograms()
public ij.measure.ResultsTable displayResultsTable()
ResultsTable
containing the histogram
data for display in ImageJ. It can be used to export the data to a CSV
file.public ArrayList<double[]> getFitAnalysis()
public JFrame plotResults()
fitResults()
method was called before, the fits are also drawn.JFrame
containing the histogram plots, which
setVisible(boolean) method must be called in order to be
displayedpublic void fitHistograms()
params_from_fit
field. The goodness of fit will be stored in
goodness_of_fit
.public JFrame displayFitAnalysis()
JTable
.JFrame
containing the table; its setVisible(boolean)
method must be called in order to be displayedpublic void setImagePlus(ij.ImagePlus imp)
histograms
to null.imp
- the image.public ij.ImagePlus getImagePlus()
public ArrayList<double[]> getFitParameters()
computeHistograms()
was not called, null
is returned.
The double array is organized as follow, for the fitting model y = a + (b-a)*exp(-(x-c)*(x-c)/(2*d*d))
getGoodnessOfFit()
,
getHistograms()
,
getBins()
public double[] getGoodnessOfFit()
computeHistograms()
was not called,
null is returned.getFitParameters()
,
getHistograms()
,
getBins()
public ArrayList<double[]> getHistograms()
computeHistograms()
was not called before.getBins()
,
getFitParameters()
,
getGoodnessOfFit()
public double[] getBins()
getHistograms()
,
getFitParameters()
,
getGoodnessOfFit()
public void setBinNumber(int nbins)
histograms
field to null.nbins
- the number of bins.public int getBinNumber()
public void setBinStart(double bin_start)
histograms
field to null.bin_start
- the bin start.public double getBinStart()
public void setBinRange(double bin_start, double bin_end)
histograms
field to null.bin_start
- the bin start.bin_end
- the bin end.public double getBinEnd()
public void setMethod(Directionality_.AnalysisMethod method)
histograms
field to null.method
- the analysis method.Directionality_.AnalysisMethod
public Directionality_.AnalysisMethod getMethod()
public void setDebugFlag(boolean flag)
flag
- the debug flag.public void setBuildOrientationMapFlag(boolean flag)
flag
- whether the orientation map shall be built.public ij.ImageStack getOrientationMap()
ImageStack
, one slice per slice
in the source image. Return null if the orientation map flag was not set,
or if computation was not done.public static final ij.ImagePlus generateColorWheel(double angle_start, double angle_end)
protected static final void addColorMouseListener(ImageCanvas canvas, double angle_start, double angle_end)
protected static final double[] prepareBins(int n, double first, double last)
n
- the number of elements to generatefirst
- the angle of the first bin, in degreeslast
- the angle of the last bin, in degreesprotected static final String parseArgumentString(String argument_string, String command_str)
setup(String, ImagePlus)
method.
Not as clever as it could be.argument_string
- the argument string to parsecommand_str
- the command to search forprotected static final ij.process.FloatProcessor displayLog(ij.process.FloatProcessor ip)
FloatProcessor
given in argument. Usefull to display power
spectrum.ip
- the source FloatProcessorFloatProcessor
protected static final double[] getBlackmanPeriodicWindow1D(int n)
n
- the number of point in the windowgetBlackmanProcessor(int, int)
protected static final ij.process.FloatProcessor getBlackmanProcessor(int nx, int ny)
nx
- the width in pixel of the desired windowny
- the hirght in pixel of the desired windowgetBlackmanPeriodicWindow1D(int)
protected static final ij.process.FloatProcessor makeRMatrix(int nx, int ny)
nx
- the width in pixel of the desired matrixny
- the height in pixel of the desired matrixmakeThetaMatrix(int, int)
protected static final ij.process.FloatProcessor makeThetaMatrix(int nx, int ny)
nx
- the width in pixel of the desired matrixny
- the height in pixel of the desired matrixmakeRMatrix(int, int)
protected static final LookupPaintScale createLUT(int ncol)
ncol
- the number of colors in the LUTpublic static void main(String[] args)
Copyright © 2015–2021 Fiji. All rights reserved.