use of ij.gui.Plot in project GDSC-SMLM by aherbert.
the class Fire method showFrcTimeEvolution.
private void showFrcTimeEvolution(String name, double fireNumber, ThresholdMethod thresholdMethod, double fourierImageScale, int imageSize) {
IJ.showStatus("Calculating FRC time evolution curve...");
// Sort by time
results.sort();
final int nSteps = 10;
int maxT = results.getLastFrame();
if (maxT == 0) {
maxT = results.size();
}
final int step = maxT / nSteps;
final TDoubleArrayList x = new TDoubleArrayList();
final TDoubleArrayList y = new TDoubleArrayList();
double yMin = fireNumber;
double yMax = fireNumber;
final MemoryPeakResults newResults = new MemoryPeakResults();
newResults.copySettings(results);
int index = 0;
final PeakResult[] list = results.toArray();
for (int t = step; t <= maxT - step; t += step) {
while (index < list.length) {
final PeakResult r = list[index];
if (r.getFrame() <= t) {
newResults.add(r);
index++;
} else {
break;
}
}
x.add(t);
final Fire f = this.copy();
final FireResult result = f.calculateFireNumber(fourierMethod, samplingMethod, thresholdMethod, fourierImageScale, imageSize);
final double fire = (result == null) ? 0 : result.fireNumber;
y.add(fire);
yMin = Math.min(yMin, fire);
yMax = Math.max(yMax, fire);
}
// Add the final fire number
x.add(maxT);
y.add(fireNumber);
final double[] xValues = x.toArray();
final double[] yValues = y.toArray();
String units = "px";
if (results.getCalibration() != null) {
nmPerUnit = results.getNmPerPixel();
units = "nm";
}
final String title = name + " FRC Time Evolution";
final Plot plot = new Plot(title, "Frames", "Resolution (" + units + ")");
final double range = Math.max(1, yMax - yMin) * 0.05;
plot.setLimits(xValues[0], xValues[xValues.length - 1], yMin - range, yMax + range);
plot.setColor(Color.red);
plot.addPoints(xValues, yValues, Plot.CONNECTED_CIRCLES);
ImageJUtils.display(title, plot);
}
use of ij.gui.Plot in project GDSC-SMLM by aherbert.
the class FilterAnalysis method showPlots.
private void showPlots() {
if (plots.isEmpty()) {
return;
}
// Display the top N plots
final int[] list = new int[plots.size()];
int index = 0;
for (final NamedPlot p : plots) {
final Plot plot = new Plot(p.name, p.xAxisName, "Jaccard");
plot.addPoints(p.xValues, p.yValues, Plot.LINE);
plot.setLimits(p.xValues[0], p.xValues[p.xValues.length - 1], 0, 1);
plot.setColor(Color.RED);
plot.draw();
plot.setColor(Color.BLUE);
plot.addPoints(p.xValues, p.yValues, Plot.CROSS);
final PlotWindow plotWindow = ImageJUtils.display(p.name, plot);
list[index++] = plotWindow.getImagePlus().getID();
}
WindowOrganiser.tileWindows(list);
}
use of ij.gui.Plot in project GDSC-SMLM by aherbert.
the class EmGainAnalysis method plotPmf.
@SuppressWarnings("unused")
private void plotPmf() {
if (!showPmfDialog()) {
return;
}
final double step = getStepSize(settings.settingPhotons, settings.settingGain, settings.settingNoise);
final Pdf pdf = pdf(0, step, settings.settingPhotons, settings.settingGain, settings.settingNoise);
double[] pmf = pdf.probability;
double yMax = MathUtils.max(pmf);
// Get the approximation
LikelihoodFunction fun;
switch(settings.approximationType) {
case 3:
fun = new PoissonFunction(1.0 / settings.settingGain);
break;
case 2:
// Use adaptive normalisation
fun = PoissonGaussianFunction2.createWithStandardDeviation(1.0 / settings.settingGain, settings.settingNoise);
break;
case 1:
// Create Poisson-Gamma (no Gaussian noise)
fun = createPoissonGammaGaussianFunction(0);
break;
case 0:
default:
fun = createPoissonGammaGaussianFunction(settings.settingNoise);
}
double expected = settings.settingPhotons;
if (settings.settingOffset != 0) {
expected += settings.settingOffset * expected / 100.0;
}
// Normalise
final boolean normalise = false;
if (normalise) {
final double sum = MathUtils.sum(pmf);
for (int i = pmf.length; i-- > 0; ) {
pmf[i] /= sum;
}
}
// Get CDF
double sum = 0;
double sum2 = 0;
double[] x = pdf.x;
double[] fvalues = new double[x.length];
double[] cdf1 = new double[pmf.length];
double[] cdf2 = new double[pmf.length];
for (int i = 0; i < cdf1.length; i++) {
sum += pmf[i] * step;
cdf1[i] = sum;
fvalues[i] = fun.likelihood(x[i], expected);
sum2 += fvalues[i] * step;
cdf2[i] = sum2;
}
// Truncate x for plotting
int max = 0;
double plimit = 1 - settings.tail;
while (sum < plimit && max < pmf.length) {
sum += pmf[max] * step;
if (sum > 0.5 && pmf[max] == 0) {
break;
}
max++;
}
int min = pmf.length;
sum = 0;
plimit = 1 - settings.head;
while (sum < plimit && min > 0) {
min--;
sum += pmf[min] * step;
if (sum > 0.5 && pmf[min] == 0) {
break;
}
}
pmf = Arrays.copyOfRange(pmf, min, max);
x = Arrays.copyOfRange(x, min, max);
fvalues = Arrays.copyOfRange(fvalues, min, max);
if (settings.showApproximation) {
yMax = MathUtils.maxDefault(yMax, fvalues);
}
final String label = String.format("Gain=%s, noise=%s, photons=%s", MathUtils.rounded(settings.settingGain), MathUtils.rounded(settings.settingNoise), MathUtils.rounded(settings.settingPhotons));
final Plot plot = new Plot("PMF", "ADUs", "p");
plot.setLimits(x[0], x[x.length - 1], 0, yMax);
plot.setColor(Color.red);
plot.addPoints(x, pmf, Plot.LINE);
if (settings.showApproximation) {
plot.setColor(Color.blue);
plot.addPoints(x, fvalues, Plot.LINE);
}
plot.setColor(Color.magenta);
plot.drawLine(settings.settingPhotons * settings.settingGain, 0, settings.settingPhotons * settings.settingGain, yMax);
plot.setColor(Color.black);
plot.addLabel(0, 0, label);
final PlotWindow win1 = ImageJUtils.display("PMF", plot);
// Plot the difference between the actual and approximation
final double[] delta = new double[fvalues.length];
for (int i = 0; i < fvalues.length; i++) {
if (pmf[i] == 0 && fvalues[i] == 0) {
continue;
}
if (settings.relativeDelta) {
delta[i] = DoubleEquality.relativeError(fvalues[i], pmf[i]) * Math.signum(fvalues[i] - pmf[i]);
} else {
delta[i] = fvalues[i] - pmf[i];
}
}
final Plot plot2 = new Plot("PMF delta", "ADUs", (settings.relativeDelta) ? "Relative delta" : "delta");
final double[] limits = MathUtils.limits(delta);
plot2.setLimits(x[0], x[x.length - 1], limits[0], limits[1]);
plot2.setColor(Color.red);
plot2.addPoints(x, delta, Plot.LINE);
plot2.setColor(Color.magenta);
plot2.drawLine(settings.settingPhotons * settings.settingGain, limits[0], settings.settingPhotons * settings.settingGain, limits[1]);
plot2.setColor(Color.black);
plot2.addLabel(0, 0, label + ((settings.settingOffset == 0) ? "" : ", expected = " + MathUtils.rounded(expected / settings.settingGain)));
final WindowOrganiser wo = new WindowOrganiser();
final PlotWindow win2 = ImageJUtils.display("PMF delta", plot2, wo);
if (wo.isNotEmpty()) {
final Point p2 = win1.getLocation();
p2.y += win1.getHeight();
win2.setLocation(p2);
}
// Plot the CDF of each distribution.
// Compute the Kolmogorov distance as the supremum (maximum)
// difference between the two cumulative probability distributions.
// https://en.wikipedia.org/wiki/Kolmogorov%E2%80%93Smirnov_test
double kolmogorovDistance = 0;
double xd = x[0];
for (int i = 0; i < cdf1.length; i++) {
final double dist = Math.abs(cdf1[i] - cdf2[i]);
if (kolmogorovDistance < dist) {
kolmogorovDistance = dist;
xd = pdf.x[i];
}
}
cdf1 = Arrays.copyOfRange(cdf1, min, max);
cdf2 = Arrays.copyOfRange(cdf2, min, max);
final Plot plot3 = new Plot("CDF", "ADUs", "p");
yMax = 1.05;
plot3.setLimits(x[0], x[x.length - 1], 0, yMax);
plot3.setColor(Color.red);
plot3.addPoints(x, cdf1, Plot.LINE);
plot3.setColor(Color.blue);
plot3.addPoints(x, cdf2, Plot.LINE);
plot3.setColor(Color.magenta);
plot3.drawLine(settings.settingPhotons * settings.settingGain, 0, settings.settingPhotons * settings.settingGain, yMax);
plot3.drawDottedLine(xd, 0, xd, yMax, 2);
plot3.setColor(Color.black);
plot3.addLabel(0, 0, label + ", Kolmogorov distance = " + MathUtils.rounded(kolmogorovDistance) + " @ " + xd);
plot3.addLegend("CDF\nApprox");
final int size = wo.size();
final PlotWindow win3 = ImageJUtils.display("CDF", plot3, wo);
if (size != wo.size()) {
final Point p2 = win1.getLocation();
p2.x += win1.getWidth();
win3.setLocation(p2);
}
}
use of ij.gui.Plot in project GDSC-SMLM by aherbert.
the class BenchmarkFilterAnalysis method showPlots.
private void showPlots() {
if (filterAnalysisResult.plots.isEmpty()) {
return;
}
// Display the top N plots
final int[] list = new int[filterAnalysisResult.plots.size()];
int index = 0;
for (final NamedPlot p : filterAnalysisResult.plots) {
final Plot plot = new Plot(p.name, p.xAxisName, Settings.COLUMNS[settings.scoreIndex]);
plot.setLimits(p.xValues[0], p.xValues[p.xValues.length - 1], 0, 1);
plot.setColor(Color.RED);
plot.addPoints(p.xValues, p.yValues, Plot.LINE);
plot.setColor(Color.BLUE);
plot.addPoints(p.xValues, p.yValues, Plot.CROSS);
final PlotWindow plotWindow = ImageJUtils.display(p.name, plot);
list[index++] = plotWindow.getImagePlus().getID();
}
WindowOrganiser.tileWindows(list);
}
use of ij.gui.Plot in project GDSC-SMLM by aherbert.
the class TraceDiffusion method plotMsd.
private Plot plotMsd(double[] x, double[] y, double[] sd, String title) {
if (settings.saveRawData) {
saveMsd(x, y, sd);
}
final Plot plot = new Plot(title, "Time (s)", "Distance (um^2)");
plot.addPoints(x, y, Plot.LINE);
// Set limits before any plotting
double max = 0;
for (int i = 1; i < x.length; i++) {
final double value = y[i] + sd[i];
max = Math.max(max, value);
}
plot.setLimits(0, x[x.length - 1] + exposureTime * 0.5, 0, max);
plot.setColor(Color.blue);
for (int i = 1; i < x.length; i++) {
plot.drawLine(x[i], y[i] - sd[i], x[i], y[i] + sd[i]);
}
plot.setColor(Color.red);
display(title, plot);
return plot;
}
Aggregations