Search in sources :

Example 1 with ComplexDoubleType

use of net.imglib2.type.numeric.complex.ComplexDoubleType in project imagej-ops by imagej.

the class FFTTest method testPadShiftKernel.

@Test
@SuppressWarnings("unchecked")
public void testPadShiftKernel() {
    long[] dims = new long[] { 1024, 1024 };
    Img<ComplexDoubleType> test = ops.create().img(new FinalDimensions(dims), new ComplexDoubleType());
    RandomAccessibleInterval<ComplexDoubleType> shift = (RandomAccessibleInterval<ComplexDoubleType>) ops.run(PadShiftKernel.class, test, new FinalDimensions(dims));
    RandomAccessibleInterval<ComplexDoubleType> shift2 = (RandomAccessibleInterval<ComplexDoubleType>) ops.run(PadShiftKernelFFTMethods.class, test, new FinalDimensions(dims));
    // assert there was no additional padding done by PadShiftKernel
    assertEquals(1024, shift.dimension(0));
    // assert that PadShiftKernelFFTMethods padded to the FFTMethods fast size
    assertEquals(1120, shift2.dimension(0));
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) PadShiftKernelFFTMethods(net.imagej.ops.filter.pad.PadShiftKernelFFTMethods) ComplexDoubleType(net.imglib2.type.numeric.complex.ComplexDoubleType) PadShiftKernel(net.imagej.ops.filter.pad.PadShiftKernel) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 2 with ComplexDoubleType

use of net.imglib2.type.numeric.complex.ComplexDoubleType in project imagej-ops by imagej.

the class CreateKernel2ndDerivBiGaussTest method testKernel2ndDerivBiGauss.

@Test
public void testKernel2ndDerivBiGauss() {
    final double sigma = 3.0;
    final double[] sigmas = { sigma, 0.5 * sigma };
    // test the main convenience function:
    RandomAccessibleInterval<DoubleType> kernelD = ops.create().kernel2ndDerivBiGauss(sigmas, 2);
    // sizes are okay?
    assertEquals(19, kernelD.dimension(0));
    assertEquals(19, kernelD.dimension(1));
    // is value at the centre the expected one?
    final long[] position = { kernelD.dimension(0) / 2, kernelD.dimension(1) / 2 };
    RandomAccess<DoubleType> samplerD = kernelD.randomAccess();
    samplerD.setPosition(position);
    assertEquals(-0.01477, samplerD.get().getRealDouble(), 0.00005);
    // is value at the centre local minimum?
    final double[] values = new double[5];
    values[0] = samplerD.get().getRealDouble();
    samplerD.move(1, 0);
    values[1] = samplerD.get().getRealDouble();
    samplerD.move(-2, 0);
    values[2] = samplerD.get().getRealDouble();
    samplerD.move(1, 0);
    samplerD.move(1, 1);
    values[3] = samplerD.get().getRealDouble();
    samplerD.move(-2, 1);
    values[4] = samplerD.get().getRealDouble();
    assertEquals(1.0, values[1] - values[0], 0.999);
    assertEquals(1.0, values[2] - values[0], 0.999);
    assertEquals(1.0, values[3] - values[0], 0.999);
    assertEquals(1.0, values[4] - values[0], 0.999);
    // is consistency checking okay?
    int wasCaught = 0;
    try {
        final double[] shortSigmas = { 2.0 * sigma };
        kernelD = ops.create().kernel2ndDerivBiGauss(shortSigmas, 2);
    } catch (IllegalArgumentException e) {
        ++wasCaught;
    }
    try {
        final double[] negativeSigmas = { -1.0, 0.0 };
        kernelD = ops.create().kernel2ndDerivBiGauss(negativeSigmas, 2);
    } catch (IllegalArgumentException e) {
        ++wasCaught;
    }
    try {
        // wrong dimensionality
        kernelD = ops.create().kernel2ndDerivBiGauss(sigmas, 0);
    } catch (IllegalArgumentException e) {
        ++wasCaught;
    }
    assertEquals(3, wasCaught);
    // does the general kernel calculation work?
    // (should be pure real kernel)
    RandomAccessibleInterval<ComplexDoubleType> kernelCD = ops.create().kernel2ndDerivBiGauss(sigmas, 2, new ComplexDoubleType());
    RandomAccess<ComplexDoubleType> samplerCD = kernelCD.randomAccess();
    samplerCD.setPosition(position);
    assertEquals(0.0, samplerCD.get().getImaginaryDouble(), 0.00001);
    // general plugin system works?
    // @SuppressWarnings("unchecked")
    kernelCD = (RandomAccessibleInterval<ComplexDoubleType>) ops.run(Ops.Create.Kernel2ndDerivBiGauss.class, sigmas, 3, new ComplexDoubleType());
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) ComplexDoubleType(net.imglib2.type.numeric.complex.ComplexDoubleType) ComplexDoubleType(net.imglib2.type.numeric.complex.ComplexDoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 3 with ComplexDoubleType

use of net.imglib2.type.numeric.complex.ComplexDoubleType in project imagej-ops by imagej.

the class CreateKernelBiGaussTest method testKernelBiGauss.

@Test
public void testKernelBiGauss() {
    final double sigma = 3.0;
    final double[] sigmas = { sigma, 0.5 * sigma };
    // test the main convenience function:
    RandomAccessibleInterval<DoubleType> kernelD = ops.create().kernelBiGauss(sigmas, 2);
    // sizes are okay?
    assertEquals(13, kernelD.dimension(0));
    assertEquals(13, kernelD.dimension(1));
    // is value at the centre the expected one?
    final long[] position = { kernelD.dimension(0) / 2, kernelD.dimension(1) / 2 };
    RandomAccess<DoubleType> samplerD = kernelD.randomAccess();
    samplerD.setPosition(position);
    assertEquals(0.09265, samplerD.get().getRealDouble(), 0.00005);
    // is value at the centre local maximum?
    final double[] values = new double[5];
    values[0] = samplerD.get().getRealDouble();
    samplerD.move(1, 0);
    values[1] = samplerD.get().getRealDouble();
    samplerD.move(-2, 0);
    values[2] = samplerD.get().getRealDouble();
    samplerD.move(1, 0);
    samplerD.move(1, 1);
    values[3] = samplerD.get().getRealDouble();
    samplerD.move(-2, 1);
    values[4] = samplerD.get().getRealDouble();
    assertEquals(1.0, values[0] - values[1], 0.999);
    assertEquals(1.0, values[0] - values[2], 0.999);
    assertEquals(1.0, values[0] - values[3], 0.999);
    assertEquals(1.0, values[0] - values[4], 0.999);
    // is consistency checking okay?
    int wasCaught = 0;
    try {
        final double[] shortSigmas = { 2.0 * sigma };
        kernelD = ops.create().kernelBiGauss(shortSigmas, 2);
    } catch (IllegalArgumentException e) {
        ++wasCaught;
    }
    try {
        final double[] negativeSigmas = { -1.0, 0.0 };
        kernelD = ops.create().kernelBiGauss(negativeSigmas, 2);
    } catch (IllegalArgumentException e) {
        ++wasCaught;
    }
    try {
        // wrong dimensionality
        kernelD = ops.create().kernelBiGauss(sigmas, 0);
    } catch (IllegalArgumentException e) {
        ++wasCaught;
    }
    assertEquals(3, wasCaught);
    // does the general kernel calculation work?
    // (should be pure real kernel)
    RandomAccessibleInterval<ComplexDoubleType> kernelCD = ops.create().kernelBiGauss(sigmas, 2, new ComplexDoubleType());
    RandomAccess<ComplexDoubleType> samplerCD = kernelCD.randomAccess();
    samplerCD.setPosition(position);
    assertEquals(0.0, samplerCD.get().getImaginaryDouble(), 0.00001);
    // general plugin system works?
    // @SuppressWarnings("unchecked")
    kernelCD = (RandomAccessibleInterval<ComplexDoubleType>) ops.run(Ops.Create.KernelBiGauss.class, sigmas, 3, new ComplexDoubleType());
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) ComplexDoubleType(net.imglib2.type.numeric.complex.ComplexDoubleType) ComplexDoubleType(net.imglib2.type.numeric.complex.ComplexDoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Aggregations

AbstractOpTest (net.imagej.ops.AbstractOpTest)3 ComplexDoubleType (net.imglib2.type.numeric.complex.ComplexDoubleType)3 Test (org.junit.Test)3 DoubleType (net.imglib2.type.numeric.real.DoubleType)2 PadShiftKernel (net.imagej.ops.filter.pad.PadShiftKernel)1 PadShiftKernelFFTMethods (net.imagej.ops.filter.pad.PadShiftKernelFFTMethods)1 FinalDimensions (net.imglib2.FinalDimensions)1 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)1