Search in sources :

Example 1 with DataEstimator

use of uk.ac.sussex.gdsc.smlm.engine.DataEstimator in project GDSC-SMLM by aherbert.

the class BackgroundEstimator method drawPlot.

/**
 * Build a plot of the noise estimate from the current frame. Limit the preview to 100 frames.
 */
private void drawPlot() {
    IJ.showStatus("Estimating background ...");
    final int start = imp.getCurrentSlice();
    final int end = Math.min(imp.getStackSize(), start + 100);
    final int size = end - start + 1;
    final double[] xValues = new double[size];
    final double[] noise1 = new double[size];
    final double[] noise2 = new double[size];
    final double[] background = new double[size];
    final double[] threshold = new double[size];
    final double[] percentile = new double[size];
    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);
        final DataEstimator de = new DataEstimator(buffer, bounds.width, bounds.height);
        de.setFraction(settings.fraction);
        de.setHistogramSize(settings.histogramSize);
        de.setThresholdMethod(settings.thresholdMethod);
        xValues[i] = slice;
        try {
            noise1[i] = de.getNoise();
            noise2[i] = de.getNoise(FitProtosHelper.convertNoiseEstimatorMethod(settings.noiseMethod));
            background[i] = de.getBackground();
            threshold[i] = de.getThreshold();
            percentile[i] = de.getPercentile(settings.percentile);
        } catch (final Exception ex) {
            throw new DataException("Failed to estimate the background", ex);
        }
    }
    IJ.showProgress(1);
    IJ.showStatus("Plotting background ...");
    final WindowOrganiser wo = new WindowOrganiser();
    plot(wo, xValues, noise1, noise2, null, "Noise", "Background Noise", "Global Noise", null);
    plot(wo, xValues, background, threshold, percentile, "Background", "Background", "Threshold", "Percentile");
    wo.tile();
    IJ.showStatus("");
}
Also used : ImageProcessor(ij.process.ImageProcessor) DataException(uk.ac.sussex.gdsc.core.data.DataException) ImageStack(ij.ImageStack) Rectangle(java.awt.Rectangle) WindowOrganiser(uk.ac.sussex.gdsc.core.ij.plugin.WindowOrganiser) DataEstimator(uk.ac.sussex.gdsc.smlm.engine.DataEstimator) DataException(uk.ac.sussex.gdsc.core.data.DataException)

Example 2 with DataEstimator

use of uk.ac.sussex.gdsc.smlm.engine.DataEstimator in project GDSC-SMLM by aherbert.

the class BackgroundEstimator method run.

@Override
public void run(ImageProcessor ip) {
    // Perform all methods and add to the results
    final double[] result = new double[8];
    int index = 0;
    result[index++] = (pfr == null) ? 1 : pfr.getSliceNumber();
    final Rectangle bounds = ip.getRoi();
    final float[] buffer = ImageJImageConverter.getData(ip.getPixels(), ip.getWidth(), ip.getHeight(), bounds, null);
    final DataEstimator de = new DataEstimator(buffer, bounds.width, bounds.height);
    de.setFraction(settings.fraction);
    de.setHistogramSize(settings.histogramSize);
    de.setThresholdMethod(settings.thresholdMethod);
    result[index++] = de.isBackgroundRegion() ? 1 : 0;
    result[index++] = de.getNoise();
    result[index++] = de.getNoise(FitProtosHelper.convertNoiseEstimatorMethod(settings.noiseMethod));
    result[index++] = de.getBackground();
    result[index++] = de.getThreshold();
    result[index++] = de.getBackgroundSize();
    result[index] = de.getPercentile(settings.percentile);
    results.add(result);
}
Also used : Rectangle(java.awt.Rectangle) DataEstimator(uk.ac.sussex.gdsc.smlm.engine.DataEstimator)

Aggregations

Rectangle (java.awt.Rectangle)2 DataEstimator (uk.ac.sussex.gdsc.smlm.engine.DataEstimator)2 ImageStack (ij.ImageStack)1 ImageProcessor (ij.process.ImageProcessor)1 DataException (uk.ac.sussex.gdsc.core.data.DataException)1 WindowOrganiser (uk.ac.sussex.gdsc.core.ij.plugin.WindowOrganiser)1