use of uk.ac.sussex.gdsc.smlm.data.config.FitProtos.NoiseEstimatorMethod in project GDSC-SMLM by aherbert.
the class Noise method drawPlot.
/**
* Build a plot of the noise estimate from the current frame. Limit the preview to 100 frames.
*/
private void drawPlot() {
final NoiseEstimatorMethod[] values = SettingsManager.getNoiseEstimatorMethodValues();
final NoiseEstimator.Method method1 = FitProtosHelper.convertNoiseEstimatorMethod(values[settings.algorithm]);
final NoiseEstimator.Method method2 = FitProtosHelper.convertNoiseEstimatorMethod(values[settings.algorithm2]);
IJ.showStatus("Estimating noise ...");
final boolean twoMethods = method1 != method2;
final boolean preserveResiduals = method1.name().contains("Residuals") && method2.name().contains("Residuals") && twoMethods;
final int current = imp.getCurrentSlice();
final int stackSize = imp.getStackSize();
final int preview = 100;
int start = current;
int end = current + preview;
if (end > stackSize) {
final int shift = end - stackSize;
start -= shift;
end = stackSize;
start = Math.max(1, start);
}
final int size = end - start + 1;
final double[] xValues = new double[size];
final double[] yValues1 = new double[size];
final double[] yValues2 = (twoMethods) ? new double[size] : null;
final ImageStack stack = imp.getImageStack();
final Rectangle bounds = imp.getProcessor().getRoi();
float[] buffer = null;
for (int slice = start, i = 0; slice <= end; slice++, i++) {
IJ.showProgress(i, size);
final ImageProcessor ip = stack.getProcessor(slice);
buffer = ImageJImageConverter.getData(ip.getPixels(), ip.getWidth(), ip.getHeight(), bounds, buffer);
cameraModel.removeBiasAndGain(bounds, buffer);
final NoiseEstimator ne = NoiseEstimator.wrap(buffer, bounds.width, bounds.height);
ne.setPreserveResiduals(preserveResiduals);
ne.setRange(settings.lowestPixelsRange);
xValues[i] = slice;
yValues1[i] = ne.getNoise(method1);
if (yValues2 != null) {
yValues2[i] = ne.getNoise(method2);
}
}
IJ.showProgress(1);
IJ.showStatus("Plotting noise ...");
// Get limits
final double[] a = Tools.getMinMax(xValues);
final double[] b1 = Tools.getMinMax(yValues1);
if (twoMethods) {
final double[] b2 = Tools.getMinMax(yValues2);
b1[0] = Math.min(b1[0], b2[0]);
b1[1] = Math.max(b1[1], b2[1]);
}
final String title = imp.getTitle() + " Noise";
final Plot plot = new Plot(title, "Slice", yAxisTitle);
double range = b1[1] - b1[0];
if (range == 0) {
range = 1;
}
plot.setLimits(a[0], a[1], b1[0] - 0.05 * range, b1[1] + 0.05 * range);
plot.setColor(Color.blue);
plot.addPoints(xValues, yValues1, Plot.LINE);
String label = String.format("%s (Blue) = %s", trim(method1.getName()), MathUtils.rounded(Statistics.create(yValues1).getMean()));
if (twoMethods) {
plot.setColor(Color.red);
plot.addPoints(xValues, yValues2, Plot.LINE);
label += String.format(", %s (Red) = %s", trim(method2.getName()), MathUtils.rounded(Statistics.create(yValues2).getMean()));
}
plot.setColor(Color.black);
plot.addLabel(0, 0, label);
ImageJUtils.display(title, plot);
IJ.showStatus("");
}
Aggregations