Search in sources :

Example 61 with FloatProcessor

use of ij.process.FloatProcessor in project GDSC-SMLM by aherbert.

the class FrcTest method computeMirroredIsFaster.

@SeededTest
void computeMirroredIsFaster(RandomSeed seed) {
    Assumptions.assumeTrue(TestSettings.allow(TestComplexity.MEDIUM));
    // Sample lines through an image to create a structure.
    final int N = 2048;
    final double[][] data = new double[N * 2][];
    final UniformRandomProvider r = RngUtils.create(seed.getSeed());
    final SharedStateContinuousSampler gs = SamplerUtils.createGaussianSampler(r, 0, 5);
    for (int x = 0, y = 0, y2 = N, i = 0; x < N; x++, y++, y2--) {
        data[i++] = new double[] { x + gs.sample(), y + gs.sample() };
        data[i++] = new double[] { x + gs.sample(), y2 + gs.sample() };
    }
    // Create 2 images
    final Rectangle bounds = new Rectangle(0, 0, N, N);
    ImageJImagePeakResults i1 = createImage(bounds);
    ImageJImagePeakResults i2 = createImage(bounds);
    final int[] indices = SimpleArrayUtils.natural(data.length);
    PermutationSampler.shuffle(r, indices);
    for (final int i : indices) {
        final ImageJImagePeakResults image = i1;
        i1 = i2;
        i2 = image;
        image.add((float) data[i][0], (float) data[i][1], 1);
    }
    i1.end();
    i2.end();
    final ImageProcessor ip1 = i1.getImagePlus().getProcessor();
    final ImageProcessor ip2 = i2.getImagePlus().getProcessor();
    // Test
    final Frc frc = new Frc();
    FloatProcessor[] fft1;
    FloatProcessor[] 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];
    final TimingService ts = new TimingService(10);
    ts.execute(new MyTimingTask("compute") {

        @Override
        public Object run(Object data) {
            Frc.compute(numerator, absFft1, absFft2, dataA1, dataB1, dataA2, dataB2);
            return null;
        }
    });
    ts.execute(new MyTimingTask("computeMirrored") {

        @Override
        public Object run(Object data) {
            Frc.computeMirrored(N, numerator, absFft1, absFft2, dataA1, dataB1, dataA2, dataB2);
            return null;
        }
    });
    ts.execute(new MyTimingTask("computeMirroredFast") {

        @Override
        public Object run(Object data) {
            Frc.computeMirroredFast(N, numerator, absFft1, absFft2, dataA1, dataB1, dataA2, dataB2);
            return null;
        }
    });
    final int size = ts.getSize();
    ts.repeat(size);
    if (logger.isLoggable(Level.INFO)) {
        logger.info(ts.getReport(size));
    }
    // The 'Fast' method may not always be faster so just log results
    final TimingResult slow = ts.get(-3);
    final TimingResult fast = ts.get(-2);
    final TimingResult fastest = ts.get(-1);
    logger.log(TestLogUtils.getTimingRecord(slow, fastest));
    logger.log(TestLogUtils.getTimingRecord(fast, fastest));
    // It should be faster than the non mirrored version
    Assertions.assertTrue(ts.get(-1).getMean() <= ts.get(-3).getMean());
}
Also used : TimingResult(uk.ac.sussex.gdsc.test.utils.TimingResult) FloatProcessor(ij.process.FloatProcessor) SharedStateContinuousSampler(org.apache.commons.rng.sampling.distribution.SharedStateContinuousSampler) Rectangle(java.awt.Rectangle) ImageJImagePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults) ImageProcessor(ij.process.ImageProcessor) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) TimingService(uk.ac.sussex.gdsc.test.utils.TimingService) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Example 62 with FloatProcessor

use of ij.process.FloatProcessor in project GDSC-SMLM by aherbert.

the class ImageJImagePeakResultsTest method canInterpolateUpInY.

@Test
void canInterpolateUpInY() {
    final ImageJImagePeakResults r = new ImageJImagePeakResults(title, bounds, 1);
    r.setDisplayFlags(ImageJImagePeakResults.DISPLAY_WEIGHTED);
    final FloatProcessor fp = new FloatProcessor(bounds.width, bounds.height);
    begin(r);
    addValue(r, 1.5f, 1.75f, 2);
    fp.putPixelValue(1, 1, 1.5f);
    fp.putPixelValue(1, 2, 0.5f);
    r.end();
    final float[] expecteds = getImage(fp);
    final float[] actuals = getImage(r);
    Assertions.assertArrayEquals(expecteds, actuals);
}
Also used : FloatProcessor(ij.process.FloatProcessor) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest) Test(org.junit.jupiter.api.Test)

Example 63 with FloatProcessor

use of ij.process.FloatProcessor in project GDSC-SMLM by aherbert.

the class ImageJImagePeakResultsTest method canAddToSinglePixelsWithInvalidPositions.

@Test
void canAddToSinglePixelsWithInvalidPositions() {
    final ImageJImagePeakResults r = new ImageJImagePeakResults(title, bounds, 1);
    final FloatProcessor fp = new FloatProcessor(bounds.width, bounds.height);
    begin(r);
    add(fp, r, 1, 1, 1);
    add(fp, r, 1, 2, 4);
    add(fp, r, 0, 1, 2);
    for (final int x : new int[] { -1, 0, 1, bounds.width, bounds.width + 1 }) {
        for (final int y : new int[] { -1, 0, 1, bounds.height, bounds.height + 1 }) {
            add(fp, r, x, y, 1);
        }
    }
    r.end();
    final float[] expecteds = getImage(fp);
    final float[] actuals = getImage(r);
    Assertions.assertArrayEquals(expecteds, actuals);
}
Also used : FloatProcessor(ij.process.FloatProcessor) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest) Test(org.junit.jupiter.api.Test)

Example 64 with FloatProcessor

use of ij.process.FloatProcessor in project GDSC-SMLM by aherbert.

the class ImageJImagePeakResultsTest method canInterpolateDownInXyAtPixelEdge.

@Test
void canInterpolateDownInXyAtPixelEdge() {
    final ImageJImagePeakResults r = new ImageJImagePeakResults(title, bounds, 1);
    r.setDisplayFlags(ImageJImagePeakResults.DISPLAY_WEIGHTED);
    final FloatProcessor fp = new FloatProcessor(bounds.width, bounds.height);
    begin(r);
    addValue(r, 1f, 1f, 4);
    fp.putPixelValue(0, 0, 1f);
    fp.putPixelValue(0, 1, 1f);
    fp.putPixelValue(1, 0, 1f);
    fp.putPixelValue(1, 1, 1f);
    r.end();
    final float[] expecteds = getImage(fp);
    final float[] actuals = getImage(r);
    Assertions.assertArrayEquals(expecteds, actuals);
}
Also used : FloatProcessor(ij.process.FloatProcessor) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest) Test(org.junit.jupiter.api.Test)

Example 65 with FloatProcessor

use of ij.process.FloatProcessor in project GDSC-SMLM by aherbert.

the class ImageJImagePeakResultsTest method canInterpolateUpInYAtPixelEdge.

@Test
void canInterpolateUpInYAtPixelEdge() {
    final ImageJImagePeakResults r = new ImageJImagePeakResults(title, bounds, 1);
    r.setDisplayFlags(ImageJImagePeakResults.DISPLAY_WEIGHTED);
    final FloatProcessor fp = new FloatProcessor(bounds.width, bounds.height);
    begin(r);
    addValue(r, 1.5f, 2f, 2);
    fp.putPixelValue(1, 1, 1);
    fp.putPixelValue(1, 2, 1);
    r.end();
    final float[] expecteds = getImage(fp);
    final float[] actuals = getImage(r);
    Assertions.assertArrayEquals(expecteds, actuals);
}
Also used : FloatProcessor(ij.process.FloatProcessor) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest) Test(org.junit.jupiter.api.Test)

Aggregations

FloatProcessor (ij.process.FloatProcessor)174 ImageProcessor (ij.process.ImageProcessor)30 SeededTest (uk.ac.sussex.gdsc.test.junit5.SeededTest)26 Rectangle (java.awt.Rectangle)23 Test (org.junit.Test)22 ByteProcessor (ij.process.ByteProcessor)21 ShortProcessor (ij.process.ShortProcessor)20 Point (java.awt.Point)20 Test (org.junit.jupiter.api.Test)20 ImagePlus (ij.ImagePlus)19 ImageStack (ij.ImageStack)19 Future (java.util.concurrent.Future)12 ColorProcessor (ij.process.ColorProcessor)11 ArrayList (java.util.ArrayList)9 LinkedList (java.util.LinkedList)8 Fht (uk.ac.sussex.gdsc.core.ij.process.Fht)7 Point (mpicbg.models.Point)6 FHT2 (ij.process.FHT2)5 File (java.io.File)5 UniformRandomProvider (org.apache.commons.rng.UniformRandomProvider)5