Search in sources :

Example 26 with Gaussian2DFunction

use of uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction 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)

Example 27 with Gaussian2DFunction

use of uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction in project GDSC-SMLM by aherbert.

the class Image3DAlignerTest method createData.

private FloatImage3D createData(int x, int y, int z, double cx, double cy, double cz) {
    final Gaussian2DFunction f = GaussianFunctionFactory.create2D(1, x, y, GaussianFunctionFactory.FIT_ASTIGMATISM, zModel);
    final int length = x * y;
    final float[] data = new float[z * length];
    final double[] a = new double[1 + Gaussian2DFunction.PARAMETERS_PER_PEAK];
    a[Gaussian2DFunction.SIGNAL] = 1;
    a[Gaussian2DFunction.X_POSITION] = cx;
    a[Gaussian2DFunction.Y_POSITION] = cy;
    a[Gaussian2DFunction.X_SD] = 1;
    a[Gaussian2DFunction.Y_SD] = 1;
    final StandardFloatValueProcedure p = new StandardFloatValueProcedure();
    for (int zz = 0; zz < z; zz++) {
        final double dz = zz - cz;
        // if (zz == 0 || zz == z - 1)
        // logger.fine(FunctionUtils.getSupplier("%f %f %f", dz, zModel.getSx(dz), zModel.getSy(dz));
        a[Gaussian2DFunction.Z_POSITION] = dz;
        p.getValues(f, a, data, zz * length);
    }
    return new FloatImage3D(x, y, z, data);
}
Also used : Gaussian2DFunction(uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction) StandardFloatValueProcedure(uk.ac.sussex.gdsc.smlm.function.StandardFloatValueProcedure)

Example 28 with Gaussian2DFunction

use of uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction in project GDSC-SMLM by aherbert.

the class Image2DAlignerTest method createData.

private static FloatImage2D createData(int x, int y, double cx, double cy) {
    final Gaussian2DFunction f = GaussianFunctionFactory.create2D(1, x, y, GaussianFunctionFactory.FIT_ERF_FREE_CIRCLE, null);
    final double[] a = new double[1 + Gaussian2DFunction.PARAMETERS_PER_PEAK];
    a[Gaussian2DFunction.SIGNAL] = 1;
    a[Gaussian2DFunction.X_POSITION] = cx;
    a[Gaussian2DFunction.Y_POSITION] = cy;
    a[Gaussian2DFunction.X_SD] = 1.2;
    a[Gaussian2DFunction.Y_SD] = 1.1;
    final StandardFloatValueProcedure p = new StandardFloatValueProcedure();
    return new FloatImage2D(x, y, p.getValues(f, a));
}
Also used : Gaussian2DFunction(uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction) StandardFloatValueProcedure(uk.ac.sussex.gdsc.smlm.function.StandardFloatValueProcedure)

Example 29 with Gaussian2DFunction

use of uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction in project GDSC-SMLM by aherbert.

the class DoubleDht3DTest method createData.

private static DoubleDht3D createData(double cx, double cy, double cz) {
    final Gaussian2DFunction f = GaussianFunctionFactory.create2D(1, size, size, GaussianFunctionFactory.FIT_ASTIGMATISM, zModel);
    final int length = size * size;
    final double[] data = new double[size * length];
    final double[] a = new double[1 + Gaussian2DFunction.PARAMETERS_PER_PEAK];
    a[Gaussian2DFunction.SIGNAL] = 1;
    a[Gaussian2DFunction.X_POSITION] = cx;
    a[Gaussian2DFunction.Y_POSITION] = cy;
    a[Gaussian2DFunction.X_SD] = 1;
    a[Gaussian2DFunction.Y_SD] = 1;
    final StandardValueProcedure p = new StandardValueProcedure();
    for (int z = 0; z < size; z++) {
        a[Gaussian2DFunction.Z_POSITION] = z - cz;
        p.getValues(f, a, data, z * length);
    }
    return new DoubleDht3D(size, size, size, data, false);
}
Also used : Gaussian2DFunction(uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction) StandardValueProcedure(uk.ac.sussex.gdsc.smlm.function.StandardValueProcedure)

Example 30 with Gaussian2DFunction

use of uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction in project GDSC-SMLM by aherbert.

the class FloatDht3DTest method createData.

private static FloatDht3D createData(double cx, double cy, double cz) {
    final Gaussian2DFunction f = GaussianFunctionFactory.create2D(1, size, size, GaussianFunctionFactory.FIT_ASTIGMATISM, zModel);
    final int length = size * size;
    final float[] data = new float[size * length];
    final double[] a = new double[1 + Gaussian2DFunction.PARAMETERS_PER_PEAK];
    a[Gaussian2DFunction.SIGNAL] = 1;
    a[Gaussian2DFunction.X_POSITION] = cx;
    a[Gaussian2DFunction.Y_POSITION] = cy;
    a[Gaussian2DFunction.X_SD] = 1;
    a[Gaussian2DFunction.Y_SD] = 1;
    final StandardFloatValueProcedure p = new StandardFloatValueProcedure();
    for (int z = 0; z < size; z++) {
        a[Gaussian2DFunction.Z_POSITION] = z - cz;
        p.getValues(f, a, data, z * length);
    }
    return new FloatDht3D(size, size, size, data, false);
}
Also used : Gaussian2DFunction(uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction) StandardFloatValueProcedure(uk.ac.sussex.gdsc.smlm.function.StandardFloatValueProcedure)

Aggregations

Gaussian2DFunction (uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction)33 ErfGaussian2DFunction (uk.ac.sussex.gdsc.smlm.function.gaussian.erf.ErfGaussian2DFunction)7 UniformRandomProvider (org.apache.commons.rng.UniformRandomProvider)6 StandardValueProcedure (uk.ac.sussex.gdsc.smlm.function.StandardValueProcedure)5 SeededTest (uk.ac.sussex.gdsc.test.junit5.SeededTest)5 Test (org.junit.jupiter.api.Test)4 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)4 StandardFloatValueProcedure (uk.ac.sussex.gdsc.smlm.function.StandardFloatValueProcedure)4 TimingService (uk.ac.sussex.gdsc.test.utils.TimingService)4 ArrayList (java.util.ArrayList)3 GradientCalculator (uk.ac.sussex.gdsc.smlm.fitting.nonlinear.gradient.GradientCalculator)3 ValueProcedure (uk.ac.sussex.gdsc.smlm.function.ValueProcedure)3 DoubleDoubleBiPredicate (uk.ac.sussex.gdsc.test.api.function.DoubleDoubleBiPredicate)3 DenseMatrix64F (org.ejml.data.DenseMatrix64F)2 DoubleEquality (uk.ac.sussex.gdsc.core.utils.DoubleEquality)2 Statistics (uk.ac.sussex.gdsc.core.utils.Statistics)2 PoissonGradientProcedure (uk.ac.sussex.gdsc.smlm.fitting.nonlinear.gradient.PoissonGradientProcedure)2 FisherInformation (uk.ac.sussex.gdsc.smlm.function.FisherInformation)2 Gradient1Function (uk.ac.sussex.gdsc.smlm.function.Gradient1Function)2 Gradient2Function (uk.ac.sussex.gdsc.smlm.function.Gradient2Function)2