Search in sources :

Example 46 with Statistics

use of uk.ac.sussex.gdsc.core.utils.Statistics in project GDSC-SMLM by aherbert.

the class SimplePeakResultValidationData method compute.

private void compute() {
    if (noise != -1) {
        return;
    }
    final double[] spotParams = extractSpotParams(params, peakNumber);
    // Adjust to the data frame
    spotParams[Gaussian2DFunction.X_POSITION] += ox;
    spotParams[Gaussian2DFunction.Y_POSITION] += oy;
    // Add the 0.5 pixel offset to get the centre pixel
    final int x = (int) (spotParams[Gaussian2DFunction.X_POSITION] + 0.5);
    final int y = (int) (spotParams[Gaussian2DFunction.Y_POSITION] + 0.5);
    // Do not evaluate over a large region for speed.
    // Use only 50% of the Gaussian volume or 3 pixels.
    int nx = getRange(spotParams[Gaussian2DFunction.X_SD] * Gaussian2DPeakResultHelper.R_2D_50, 3);
    int ny = getRange(spotParams[Gaussian2DFunction.Y_SD] * Gaussian2DPeakResultHelper.R_2D_50, 3);
    final Rectangle r1 = new Rectangle(x - nx, y - ny, 2 * nx + 1, 2 * ny + 1);
    final Rectangle r2 = r1.intersection(new Rectangle(0, 0, maxx, maxy));
    if (r2.width * r2.height <= 1) {
        localBackground = params[Gaussian2DFunction.BACKGROUND];
        // Assume photon shot noise.
        noise = Math.sqrt(localBackground);
        return;
    }
    // Get the region of the data
    final double[] region = ic.getDoubleData(data, maxx, maxy, r2, null);
    // Compute the function in the same region.
    // Adjust the coordinates for clipping (r2 will be >= r1).
    // This effectively makes nx/ny represent the number of pixels before the centre pixel
    nx -= r2.x - r1.x;
    ny -= r2.y - r1.y;
    // Put the spot in the centre of the region
    spotParams[Gaussian2DFunction.X_POSITION] += nx - x;
    spotParams[Gaussian2DFunction.Y_POSITION] += ny - y;
    final Gaussian2DFunction f = factory.create2D(1, r2.width, r2.height);
    final double[] v = f.computeValues(spotParams);
    final Statistics stats = new Statistics();
    for (int i = 0; i < v.length; i++) {
        stats.add(region[i] - v[i]);
    }
    localBackground = stats.getMean();
    noise = stats.getStandardDeviation();
}
Also used : Gaussian2DFunction(uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction) Rectangle(java.awt.Rectangle) Statistics(uk.ac.sussex.gdsc.core.utils.Statistics)

Aggregations

Statistics (uk.ac.sussex.gdsc.core.utils.Statistics)46 StoredDataStatistics (uk.ac.sussex.gdsc.core.utils.StoredDataStatistics)16 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)11 Rectangle (java.awt.Rectangle)10 ArrayList (java.util.ArrayList)10 WindowOrganiser (uk.ac.sussex.gdsc.core.ij.plugin.WindowOrganiser)10 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)10 Plot (ij.gui.Plot)8 PeakResult (uk.ac.sussex.gdsc.smlm.results.PeakResult)8 PeakResultProcedure (uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure)7 ImagePlus (ij.ImagePlus)6 ExecutorService (java.util.concurrent.ExecutorService)6 Future (java.util.concurrent.Future)6 HistogramPlotBuilder (uk.ac.sussex.gdsc.core.ij.HistogramPlot.HistogramPlotBuilder)6 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)6 Ticker (uk.ac.sussex.gdsc.core.logging.Ticker)6 DistanceUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)6 Trace (uk.ac.sussex.gdsc.smlm.results.Trace)6 TIntArrayList (gnu.trove.list.array.TIntArrayList)5 ImageStack (ij.ImageStack)5