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();
}
Aggregations