Search in sources :

Example 11 with IJImagePeakResults

use of gdsc.smlm.ij.results.IJImagePeakResults in project GDSC-SMLM by aherbert.

the class PeakFit method initialiseFitting.

/**
	 * Set-up the fitting using all the configured properties. Prepare the output results.
	 */
public boolean initialiseFitting() {
    if (source == null)
        return false;
    // Do this to ensure the serialised configuration is correct
    updateFitConfiguration(config);
    results.setSource(source);
    if (maximaIdentification)
        results.setName(source.getName() + " (Maxima)");
    else if (fitMaxima)
        results.setName(source.getName() + " (" + getSolverName() + " Fit Maxima)");
    else
        results.setName(source.getName() + " (" + getSolverName() + ")");
    results.setBounds(bounds);
    Calibration cal = calibration.clone();
    // Account for the frame integration
    // TODO - Should we change this so that if integrate frames is used then the data 
    // are converted to ExtendedPeakResult with a start and end frame
    //cal.exposureTime *= integrateFrames;
    //if (interlacedData)
    //{
    //	cal.exposureTime *= ((double)dataBlock / (dataBlock + dataSkip));
    //}
    results.setCalibration(cal);
    results.setConfiguration(XmlUtils.toXML(config));
    addMemoryResults(results, false);
    addImageResults(results);
    addFileResults(results);
    addTableResults(results);
    addDefaultResults(results);
    results.begin();
    if (simpleFit && showImage) {
        for (PeakResults r : results.toArray()) {
            if (r instanceof IJImagePeakResults) {
                ImagePlus i = ((IJImagePeakResults) r).getImagePlus();
                Utils.log("Super-resolution image title = " + i.getTitle());
                WindowManager.toFront(i.getWindow());
            }
        }
    }
    return true;
}
Also used : PeakResults(gdsc.smlm.results.PeakResults) IJTablePeakResults(gdsc.smlm.ij.results.IJTablePeakResults) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) IJImagePeakResults(gdsc.smlm.ij.results.IJImagePeakResults) BinaryFilePeakResults(gdsc.smlm.results.BinaryFilePeakResults) MALKFilePeakResults(gdsc.smlm.results.MALKFilePeakResults) FilePeakResults(gdsc.smlm.results.FilePeakResults) Calibration(gdsc.smlm.results.Calibration) IJImagePeakResults(gdsc.smlm.ij.results.IJImagePeakResults) ImagePlus(ij.ImagePlus)

Example 12 with IJImagePeakResults

use of gdsc.smlm.ij.results.IJImagePeakResults in project GDSC-SMLM by aherbert.

the class FRCTest method canComputeMirrored.

@Test
public void canComputeMirrored() {
    // Sample lines through an image to create a structure.
    int size = 1024;
    double[][] data = new double[size * 2][];
    RandomGenerator r = new Well19937c(30051977);
    for (int x = 0, y = 0, y2 = size, i = 0; x < size; x++, y++, y2--) {
        data[i++] = new double[] { x + r.nextGaussian() * 5, y + r.nextGaussian() * 5 };
        data[i++] = new double[] { x + r.nextGaussian() * 5, y2 + r.nextGaussian() * 5 };
    }
    // Create 2 images
    Rectangle bounds = new Rectangle(0, 0, size, size);
    IJImagePeakResults i1 = createImage(bounds);
    IJImagePeakResults i2 = createImage(bounds);
    int[] indices = Utils.newArray(data.length, 0, 1);
    MathArrays.shuffle(indices, r);
    for (int i : indices) {
        IJImagePeakResults image = i1;
        i1 = i2;
        i2 = image;
        image.add((float) data[i][0], (float) data[i][1], 1);
    }
    i1.end();
    i2.end();
    ImageProcessor ip1 = i1.getImagePlus().getProcessor();
    ImageProcessor ip2 = i2.getImagePlus().getProcessor();
    // Test
    FRC frc = new FRC();
    FloatProcessor[] fft1, fft2;
    fft1 = frc.getComplexFFT(ip1);
    fft2 = frc.getComplexFFT(ip2);
    float[] dataA1 = (float[]) fft1[0].getPixels();
    float[] dataB1 = (float[]) fft1[1].getPixels();
    float[] dataA2 = (float[]) fft2[0].getPixels();
    float[] dataB2 = (float[]) fft2[1].getPixels();
    float[] numeratorE = new float[dataA1.length];
    float[] absFFT1E = new float[dataA1.length];
    float[] absFFT2E = new float[dataA1.length];
    FRC.compute(numeratorE, absFFT1E, absFFT2E, dataA1, dataB1, dataA2, dataB2);
    Assert.assertTrue("numeratorE", FRC.checkSymmetry(numeratorE, size));
    Assert.assertTrue("absFFT1E", FRC.checkSymmetry(absFFT1E, size));
    Assert.assertTrue("absFFT2E", FRC.checkSymmetry(absFFT2E, size));
    float[] numeratorA = new float[dataA1.length];
    float[] absFFT1A = new float[dataA1.length];
    float[] absFFT2A = new float[dataA1.length];
    FRC.computeMirrored(size, numeratorA, absFFT1A, absFFT2A, dataA1, dataB1, dataA2, dataB2);
    //for (int y=0, i=0; y<size; y++)
    //	for (int x=0; x<size; x++, i++)
    //	{
    //		System.out.printf("[%d,%d = %d] %f ?= %f\n", x, y, i, numeratorE[i], numeratorA[i]);
    //	}
    Assert.assertArrayEquals("numerator", numeratorE, numeratorA, 0);
    Assert.assertArrayEquals("absFFT1", absFFT1E, absFFT1A, 0);
    Assert.assertArrayEquals("absFFT2", absFFT2E, absFFT2A, 0);
    FRC.computeMirroredFast(size, numeratorA, absFFT1A, absFFT2A, dataA1, dataB1, dataA2, dataB2);
    // Check this.
    for (int y = 1; y < size; y++) for (int x = 1, i = y * size + 1; x < size; x++, i++) {
        Assert.assertEquals("numerator", numeratorE[i], numeratorA[i], 0);
        Assert.assertEquals("absFFT1", absFFT1E[i], absFFT1A[i], 0);
        Assert.assertEquals("absFFT2", absFFT2E[i], absFFT2A[i], 0);
    }
}
Also used : ImageProcessor(ij.process.ImageProcessor) FloatProcessor(ij.process.FloatProcessor) Rectangle(java.awt.Rectangle) Well19937c(org.apache.commons.math3.random.Well19937c) IJImagePeakResults(gdsc.smlm.ij.results.IJImagePeakResults) RandomGenerator(org.apache.commons.math3.random.RandomGenerator) Test(org.junit.Test)

Example 13 with IJImagePeakResults

use of gdsc.smlm.ij.results.IJImagePeakResults in project GDSC-SMLM by aherbert.

the class FRCTest method computeMirroredIsFaster.

@Test
public void computeMirroredIsFaster() {
    // Sample lines through an image to create a structure.
    final int size = 2048;
    double[][] data = new double[size * 2][];
    RandomGenerator r = new Well19937c(30051977);
    for (int x = 0, y = 0, y2 = size, i = 0; x < size; x++, y++, y2--) {
        data[i++] = new double[] { x + r.nextGaussian() * 5, y + r.nextGaussian() * 5 };
        data[i++] = new double[] { x + r.nextGaussian() * 5, y2 + r.nextGaussian() * 5 };
    }
    // Create 2 images
    Rectangle bounds = new Rectangle(0, 0, size, size);
    IJImagePeakResults i1 = createImage(bounds);
    IJImagePeakResults i2 = createImage(bounds);
    int[] indices = Utils.newArray(data.length, 0, 1);
    MathArrays.shuffle(indices, r);
    for (int i : indices) {
        IJImagePeakResults image = i1;
        i1 = i2;
        i2 = image;
        image.add((float) data[i][0], (float) data[i][1], 1);
    }
    i1.end();
    i2.end();
    ImageProcessor ip1 = i1.getImagePlus().getProcessor();
    ImageProcessor ip2 = i2.getImagePlus().getProcessor();
    // Test
    FRC frc = new FRC();
    FloatProcessor[] fft1, fft2;
    fft1 = frc.getComplexFFT(ip1);
    fft2 = frc.getComplexFFT(ip2);
    final float[] dataA1 = (float[]) fft1[0].getPixels();
    final float[] dataB1 = (float[]) fft1[1].getPixels();
    final float[] dataA2 = (float[]) fft2[0].getPixels();
    final float[] dataB2 = (float[]) fft2[1].getPixels();
    final float[] numerator = new float[dataA1.length];
    final float[] absFFT1 = new float[dataA1.length];
    final float[] absFFT2 = new float[dataA1.length];
    TimingService ts = new TimingService(10);
    ts.execute(new MyTimingTask("compute") {

        public Object run(Object data) {
            FRC.compute(numerator, absFFT1, absFFT2, dataA1, dataB1, dataA2, dataB2);
            return null;
        }
    });
    ts.execute(new MyTimingTask("computeMirrored") {

        public Object run(Object data) {
            FRC.computeMirrored(size, numerator, absFFT1, absFFT2, dataA1, dataB1, dataA2, dataB2);
            return null;
        }
    });
    ts.execute(new MyTimingTask("computeMirroredFast") {

        public Object run(Object data) {
            FRC.computeMirroredFast(size, numerator, absFFT1, absFFT2, dataA1, dataB1, dataA2, dataB2);
            return null;
        }
    });
    ts.repeat(ts.getSize());
    ts.report();
}
Also used : FloatProcessor(ij.process.FloatProcessor) Rectangle(java.awt.Rectangle) Well19937c(org.apache.commons.math3.random.Well19937c) IJImagePeakResults(gdsc.smlm.ij.results.IJImagePeakResults) RandomGenerator(org.apache.commons.math3.random.RandomGenerator) ImageProcessor(ij.process.ImageProcessor) TimingService(gdsc.core.test.TimingService) Test(org.junit.Test)

Example 14 with IJImagePeakResults

use of gdsc.smlm.ij.results.IJImagePeakResults in project GDSC-SMLM by aherbert.

the class SphericalDistributionTest method drawImage.

private void drawImage(boolean useRejctionMethod) {
    MemoryPeakResults results = new MemoryPeakResults();
    results.setSortAfterEnd(true);
    int radius = 10;
    Rectangle bounds = new Rectangle(0, 0, radius * 2, radius * 2);
    SphericalDistribution dist = new SphericalDistribution(radius, rand);
    dist.setUseRejectionMethod(useRejctionMethod);
    float scale = 10;
    results.begin();
    for (int i = 100000; i-- > 0; ) {
        double[] xyz = dist.next();
        int peak = (int) (1 + scale * radius + Math.round(scale * xyz[2]));
        float[] params = new float[7];
        params[Gaussian2DFunction.X_POSITION] = radius + (float) xyz[0];
        params[Gaussian2DFunction.Y_POSITION] = radius + (float) xyz[1];
        results.addf(peak, 0, 0, 0, 0, 0, params, null);
    }
    results.end();
    IJImagePeakResults image = new IJImagePeakResults((useRejctionMethod) ? "Rejection Method" : "Transformation Method", bounds, scale);
    image.setRollingWindowSize(1);
    image.begin();
    image.addAll(results.getResults());
    // Place breakpoint here in debug mode to view the image. 
    // It should have an even colour through the stack.
    image.end();
}
Also used : Rectangle(java.awt.Rectangle) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) IJImagePeakResults(gdsc.smlm.ij.results.IJImagePeakResults)

Aggregations

IJImagePeakResults (gdsc.smlm.ij.results.IJImagePeakResults)14 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)5 ImageProcessor (ij.process.ImageProcessor)5 Rectangle (java.awt.Rectangle)5 PeakResult (gdsc.smlm.results.PeakResult)3 FloatProcessor (ij.process.FloatProcessor)3 Calibration (gdsc.smlm.results.Calibration)2 PeakResults (gdsc.smlm.results.PeakResults)2 RandomGenerator (org.apache.commons.math3.random.RandomGenerator)2 Well19937c (org.apache.commons.math3.random.Well19937c)2 Test (org.junit.Test)2 TimingService (gdsc.core.test.TimingService)1 IJTablePeakResults (gdsc.smlm.ij.results.IJTablePeakResults)1 BinaryFilePeakResults (gdsc.smlm.results.BinaryFilePeakResults)1 FilePeakResults (gdsc.smlm.results.FilePeakResults)1 IdPeakResult (gdsc.smlm.results.IdPeakResult)1 MALKFilePeakResults (gdsc.smlm.results.MALKFilePeakResults)1 ImagePlus (ij.ImagePlus)1 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1