Search in sources :

Example 1 with DataEstimator

use of 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 ...");
    int start = imp.getCurrentSlice();
    int end = FastMath.min(imp.getStackSize(), start + 100);
    int size = end - start + 1;
    double[] xValues = new double[size];
    double[] noise1 = new double[size];
    double[] noise2 = new double[size];
    double[] background = new double[size];
    double[] threshold = new double[size];
    double[] percentile = new double[size];
    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 DataEstimator de = new DataEstimator(buffer, bounds.width, bounds.height);
        de.setFraction(fraction);
        de.setHistogramSize(histogramSize);
        de.setThresholdMethod(thresholdMethod);
        xValues[i] = slice;
        try {
            noise1[i] = de.getNoise();
            noise2[i] = de.getNoise(noiseMethod);
            background[i] = de.getBackground();
            threshold[i] = de.getThreshold();
            percentile[i] = de.getPercentile(BackgroundEstimator.percentile);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
    IJ.showProgress(1);
    IJ.showStatus("Plotting background ...");
    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) ImageStack(ij.ImageStack) Rectangle(java.awt.Rectangle) WindowOrganiser(ij.plugin.WindowOrganiser) DataEstimator(gdsc.smlm.engine.DataEstimator)

Example 2 with DataEstimator

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

the class BackgroundEstimator 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[8];
    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);
    final DataEstimator de = new DataEstimator(buffer, bounds.width, bounds.height);
    de.setFraction(fraction);
    de.setHistogramSize(histogramSize);
    de.setThresholdMethod(thresholdMethod);
    result[i++] = de.isBackgroundRegion() ? 1 : 0;
    result[i++] = de.getNoise();
    result[i++] = de.getNoise(noiseMethod);
    result[i++] = de.getBackground();
    result[i++] = de.getThreshold();
    result[i++] = de.getBackgroundSize();
    result[i++] = de.getPercentile(percentile);
    results.add(result);
}
Also used : Rectangle(java.awt.Rectangle) DataEstimator(gdsc.smlm.engine.DataEstimator)

Aggregations

DataEstimator (gdsc.smlm.engine.DataEstimator)2 Rectangle (java.awt.Rectangle)2 ImageStack (ij.ImageStack)1 WindowOrganiser (ij.plugin.WindowOrganiser)1 ImageProcessor (ij.process.ImageProcessor)1