Search in sources :

Example 1 with NoiseEstimator

use of gdsc.core.utils.NoiseEstimator 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() {
    NoiseEstimator.Method method1 = NoiseEstimator.Method.values()[algorithm];
    NoiseEstimator.Method method2 = NoiseEstimator.Method.values()[algorithm2];
    IJ.showStatus("Estimating noise ...");
    boolean twoMethods = method1 != method2;
    boolean preserveResiduals = method1.name().contains("Residuals") && method2.name().contains("Residuals") && twoMethods;
    int start = imp.getCurrentSlice();
    int end = FastMath.min(imp.getStackSize(), start + 100);
    int size = end - start + 1;
    double[] xValues = new double[size];
    double[] yValues1 = new double[size];
    double[] yValues2 = (twoMethods) ? new double[size] : null;
    ImageStack stack = imp.getImageStack();
    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 = ImageConverter.getData(ip.getPixels(), ip.getWidth(), ip.getHeight(), bounds, buffer);
        final NoiseEstimator ne = new NoiseEstimator(buffer, bounds.width, bounds.height);
        ne.preserveResiduals = preserveResiduals;
        ne.setRange(lowestPixelsRange);
        xValues[i] = slice;
        yValues1[i] = ne.getNoise(method1);
        if (twoMethods)
            yValues2[i] = ne.getNoise(method2);
    }
    IJ.showProgress(1);
    IJ.showStatus("Plotting noise ...");
    // Get limits
    double[] a = Tools.getMinMax(xValues);
    double[] b1 = Tools.getMinMax(yValues1);
    if (twoMethods) {
        double[] b2 = Tools.getMinMax(yValues2);
        b1[0] = FastMath.min(b1[0], b2[0]);
        b1[1] = FastMath.max(b1[1], b2[1]);
    }
    String title = imp.getTitle() + " Noise";
    Plot2 plot = new Plot2(title, "Slice", "Noise", xValues, yValues1);
    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.draw();
    String label = String.format("Blue = %s", Utils.rounded(new Statistics(yValues1).getMean()));
    if (twoMethods) {
        plot.setColor(Color.red);
        plot.addPoints(xValues, yValues2, Plot2.LINE);
        label += String.format(", Red = %s", Utils.rounded(new Statistics(yValues2).getMean()));
    }
    plot.addLabel(0, 0, label);
    Utils.display(title, plot);
    IJ.showStatus("");
}
Also used : ImageStack(ij.ImageStack) Rectangle(java.awt.Rectangle) Plot2(ij.gui.Plot2) Statistics(gdsc.core.utils.Statistics) ImageProcessor(ij.process.ImageProcessor) NoiseEstimator(gdsc.core.utils.NoiseEstimator)

Example 2 with NoiseEstimator

use of gdsc.core.utils.NoiseEstimator in project GDSC-SMLM by aherbert.

the class Noise method run.

/*
	 * (non-Javadoc)
	 * 
	 * @see ij.plugin.filter.PlugInFilter#run(ij.process.ImageProcessor)
	 */
public void run(ImageProcessor ip) {
    // Perform all methods and add to the results
    double[] result = new double[NoiseEstimator.Method.values().length + 1];
    int i = 0;
    result[i++] = (pfr == null) ? 1 : pfr.getSliceNumber();
    Rectangle bounds = ip.getRoi();
    float[] buffer = ImageConverter.getData(ip.getPixels(), ip.getWidth(), ip.getHeight(), bounds, null);
    NoiseEstimator ne = new NoiseEstimator(buffer, bounds.width, bounds.height);
    ne.preserveResiduals = true;
    for (NoiseEstimator.Method m : NoiseEstimator.Method.values()) {
        result[i++] = ne.getNoise(m);
    }
    results.add(result);
}
Also used : Rectangle(java.awt.Rectangle) NoiseEstimator(gdsc.core.utils.NoiseEstimator)

Aggregations

NoiseEstimator (gdsc.core.utils.NoiseEstimator)2 Rectangle (java.awt.Rectangle)2 Statistics (gdsc.core.utils.Statistics)1 ImageStack (ij.ImageStack)1 Plot2 (ij.gui.Plot2)1 ImageProcessor (ij.process.ImageProcessor)1