Search in sources :

Example 6 with FinalDimensions

use of net.imglib2.FinalDimensions in project imagej-ops by imagej.

the class ConvolveTest method testConvolve.

/**
 * tests fft based convolve
 */
@Test
public void testConvolve() {
    float delta = 0.0001f;
    int[] size = new int[] { 225, 167 };
    int[] kernelSize = new int[] { 27, 39 };
    long[] borderSize = new long[] { 10, 10 };
    // create an input with a small sphere at the center
    Img<FloatType> in = new ArrayImgFactory<FloatType>().create(size, new FloatType());
    placeSphereInCenter(in);
    // create a kernel with a small sphere in the center
    Img<FloatType> kernel = new ArrayImgFactory<FloatType>().create(kernelSize, new FloatType());
    placeSphereInCenter(kernel);
    // create variables to hold the image sums
    FloatType inSum = new FloatType();
    FloatType kernelSum = new FloatType();
    FloatType outSum = new FloatType();
    FloatType outSum2 = new FloatType();
    FloatType outSum3 = new FloatType();
    // calculate sum of input and kernel
    ops.stats().sum(inSum, in);
    ops.stats().sum(kernelSum, kernel);
    // convolve and calculate the sum of output
    @SuppressWarnings("unchecked") final Img<FloatType> out = (Img<FloatType>) ops.run(ConvolveFFTF.class, in, kernel, borderSize);
    // create an output for the next test
    Img<FloatType> out2 = new ArrayImgFactory<FloatType>().create(size, new FloatType());
    // create an output for the next test
    Img<FloatType> out3 = new ArrayImgFactory<FloatType>().create(size, new FloatType());
    // Op used to pad the input
    final BinaryFunctionOp<RandomAccessibleInterval<FloatType>, Dimensions, RandomAccessibleInterval<FloatType>> padOp = (BinaryFunctionOp) Functions.binary(ops, PadInputFFTMethods.class, RandomAccessibleInterval.class, RandomAccessibleInterval.class, Dimensions.class, true);
    // Op used to pad the kernel
    final BinaryFunctionOp<RandomAccessibleInterval<FloatType>, Dimensions, RandomAccessibleInterval<FloatType>> padKernelOp = (BinaryFunctionOp) Functions.binary(ops, PadShiftKernelFFTMethods.class, RandomAccessibleInterval.class, RandomAccessibleInterval.class, Dimensions.class, true);
    // Op used to create the complex FFTs
    UnaryFunctionOp<Dimensions, RandomAccessibleInterval<ComplexFloatType>> createOp = (UnaryFunctionOp) Functions.unary(ops, CreateOutputFFTMethods.class, RandomAccessibleInterval.class, Dimensions.class, new ComplexFloatType(), true);
    final int numDimensions = in.numDimensions();
    // 1. Calculate desired extended size of the image
    final long[] paddedSize = new long[numDimensions];
    // if no getBorderSize() was passed in, then extend based on kernel size
    for (int d = 0; d < numDimensions; ++d) {
        paddedSize[d] = (int) in.dimension(d) + (int) kernel.dimension(d) - 1;
    }
    RandomAccessibleInterval<FloatType> paddedInput = padOp.calculate(in, new FinalDimensions(paddedSize));
    RandomAccessibleInterval<FloatType> paddedKernel = padKernelOp.calculate(kernel, new FinalDimensions(paddedSize));
    RandomAccessibleInterval<ComplexFloatType> fftImage = createOp.calculate(new FinalDimensions(paddedSize));
    RandomAccessibleInterval<ComplexFloatType> fftKernel = createOp.calculate(new FinalDimensions(paddedSize));
    // run convolve using the rai version with the memory created above
    ops.run(ConvolveFFTC.class, out2, paddedInput, paddedKernel, fftImage, fftKernel);
    ops.run(ConvolveFFTC.class, out3, paddedInput, paddedKernel, fftImage, fftKernel, true, false);
    ops.stats().sum(outSum, Views.iterable(out));
    ops.stats().sum(outSum2, out2);
    ops.stats().sum(outSum3, out3);
    // multiply input sum by kernelSum and assert it is the same as outSum
    inSum.mul(kernelSum);
    assertEquals(inSum.get(), outSum.get(), delta);
    assertEquals(inSum.get(), outSum2.get(), delta);
    assertEquals(inSum.get(), outSum3.get(), delta);
    assertEquals(size[0], out.dimension(0));
    assertEquals(size[0], out2.dimension(0));
}
Also used : Img(net.imglib2.img.Img) ComplexFloatType(net.imglib2.type.numeric.complex.ComplexFloatType) FinalDimensions(net.imglib2.FinalDimensions) Dimensions(net.imglib2.Dimensions) BinaryFunctionOp(net.imagej.ops.special.function.BinaryFunctionOp) PadShiftKernelFFTMethods(net.imagej.ops.filter.pad.PadShiftKernelFFTMethods) Point(net.imglib2.Point) FloatType(net.imglib2.type.numeric.real.FloatType) ComplexFloatType(net.imglib2.type.numeric.complex.ComplexFloatType) FinalDimensions(net.imglib2.FinalDimensions) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) CreateOutputFFTMethods(net.imagej.ops.filter.fft.CreateOutputFFTMethods) UnaryFunctionOp(net.imagej.ops.special.function.UnaryFunctionOp) PadInputFFTMethods(net.imagej.ops.filter.pad.PadInputFFTMethods) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 7 with FinalDimensions

use of net.imglib2.FinalDimensions in project imagej-ops by imagej.

the class ConvertIIsTest method createImages.

@Before
public void createImages() {
    final FinalDimensions dims = FinalDimensions.wrap(new long[] { 10, 10 });
    in = ops.create().img(dims, new ShortType());
    addNoise(in);
    out = ops.create().img(dims, new ByteType());
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) ShortType(net.imglib2.type.numeric.integer.ShortType) ByteType(net.imglib2.type.numeric.integer.ByteType) Before(org.junit.Before)

Example 8 with FinalDimensions

use of net.imglib2.FinalDimensions in project imagej-ops by imagej.

the class CreateImgTest method testImageFactory.

@Test
public void testImageFactory() {
    final Dimensions dim = new FinalDimensions(10, 10, 10);
    @SuppressWarnings("unchecked") final Img<DoubleType> arrayImg = (Img<DoubleType>) ops.run(CreateImgFromDimsAndType.class, dim, new DoubleType(), new ArrayImgFactory<DoubleType>());
    final Class<?> arrayFactoryClass = arrayImg.factory().getClass();
    assertEquals("Image Factory: ", ArrayImgFactory.class, arrayFactoryClass);
    @SuppressWarnings("unchecked") final Img<DoubleType> cellImg = (Img<DoubleType>) ops.run(CreateImgFromDimsAndType.class, dim, new DoubleType(), new CellImgFactory<DoubleType>());
    final Class<?> cellFactoryClass = cellImg.factory().getClass();
    assertEquals("Image Factory: ", CellImgFactory.class, cellFactoryClass);
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) CreateImgFromImg(net.imagej.ops.create.img.CreateImgFromImg) Img(net.imglib2.img.Img) CellImgFactory(net.imglib2.img.cell.CellImgFactory) DoubleType(net.imglib2.type.numeric.real.DoubleType) CreateImgFromDimsAndType(net.imagej.ops.create.img.CreateImgFromDimsAndType) FinalDimensions(net.imglib2.FinalDimensions) Dimensions(net.imglib2.Dimensions) ArrayImgFactory(net.imglib2.img.array.ArrayImgFactory) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 9 with FinalDimensions

use of net.imglib2.FinalDimensions in project imagej-ops by imagej.

the class CreateKernelDiffractionTest method testKernelDiffraction.

@Test
public void testKernelDiffraction() {
    final Dimensions dims = new FinalDimensions(10, 10);
    // numerical aperture
    final double NA = 1.4;
    // wavelength
    final double lambda = 610E-09;
    // specimen refractive index
    final double ns = 1.33;
    // immersion refractive index, experimental
    final double ni = 1.5;
    // lateral pixel size
    final double resLateral = 100E-9;
    // axial pixel size
    final double resAxial = 250E-9;
    // position of particle
    final double pZ = 2000E-9D;
    // pixel type of created kernel
    final DoubleType type = new DoubleType();
    final // 
    Img<DoubleType> kernel = ops.create().kernelDiffraction(dims, NA, lambda, ns, ni, resLateral, resAxial, pZ, type);
    final double[] expected = { 0.03298495871588273, 0.04246786111102021, 0.0543588031627261, 0.06650574371357207, 0.07370280610722534, 0.07370280610722534, 0.06650574371357207, 0.0543588031627261, 0.04246786111102021, 0.03298495871588273, 0.04246786111102021, 0.05962205221267819, 0.08320071670150801, 0.10800022978800021, 0.1247473245002288, 0.1247473245002288, 0.10800022978800021, 0.08320071670150801, 0.05962205221267819, 0.04246786111102021, 0.0543588031627261, 0.08320071670150801, 0.1247473245002288, 0.1971468112729564, 0.2691722397359577, 0.2691722397359577, 0.1971468112729564, 0.1247473245002288, 0.08320071670150801, 0.0543588031627261, 0.06650574371357207, 0.10800022978800021, 0.1971468112729564, 0.40090474481128285, 0.6227157103102976, 0.6227157103102976, 0.40090474481128285, 0.1971468112729564, 0.10800022978800021, 0.06650574371357207, 0.07370280610722534, 0.1247473245002288, 0.2691722397359577, 0.6227157103102976, 1.0, 1.0, 0.6227157103102976, 0.2691722397359577, 0.1247473245002288, 0.07370280610722534, 0.07370280610722534, 0.1247473245002288, 0.2691722397359577, 0.6227157103102976, 1.0, 1.0, 0.6227157103102976, 0.2691722397359577, 0.1247473245002288, 0.07370280610722534, 0.06650574371357207, 0.10800022978800021, 0.1971468112729564, 0.40090474481128285, 0.6227157103102976, 0.6227157103102976, 0.40090474481128285, 0.1971468112729564, 0.10800022978800021, 0.06650574371357207, 0.0543588031627261, 0.08320071670150801, 0.1247473245002288, 0.1971468112729564, 0.2691722397359577, 0.2691722397359577, 0.1971468112729564, 0.1247473245002288, 0.08320071670150801, 0.0543588031627261, 0.04246786111102021, 0.05962205221267819, 0.08320071670150801, 0.10800022978800021, 0.1247473245002288, 0.1247473245002288, 0.10800022978800021, 0.08320071670150801, 0.05962205221267819, 0.04246786111102021, 0.03298495871588273, 0.04246786111102021, 0.0543588031627261, 0.06650574371357207, 0.07370280610722534, 0.07370280610722534, 0.06650574371357207, 0.0543588031627261, 0.04246786111102021, 0.03298495871588273 };
    assertArrayEquals(expected, asArray(kernel), 0.0);
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) DoubleType(net.imglib2.type.numeric.real.DoubleType) FinalDimensions(net.imglib2.FinalDimensions) Dimensions(net.imglib2.Dimensions) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 10 with FinalDimensions

use of net.imglib2.FinalDimensions in project imagej-ops by imagej.

the class Outline method createOutput.

@Override
public RandomAccessibleInterval<BitType> createOutput(final RandomAccessibleInterval<B> input, final Boolean input2) {
    final long[] dims = new long[input.numDimensions()];
    input.dimensions(dims);
    final FinalDimensions dimensions = new FinalDimensions(dims);
    return ops().create().img(dimensions, new BitType());
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) BitType(net.imglib2.type.logic.BitType)

Aggregations

FinalDimensions (net.imglib2.FinalDimensions)20 Dimensions (net.imglib2.Dimensions)9 AbstractOpTest (net.imagej.ops.AbstractOpTest)8 Test (org.junit.Test)8 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)5 Img (net.imglib2.img.Img)5 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)4 DoubleType (net.imglib2.type.numeric.real.DoubleType)4 CreateImgFromImg (net.imagej.ops.create.img.CreateImgFromImg)3 BitType (net.imglib2.type.logic.BitType)3 ByteType (net.imglib2.type.numeric.integer.ByteType)3 CreateImgFromDimsAndType (net.imagej.ops.create.img.CreateImgFromDimsAndType)2 PadShiftKernelFFTMethods (net.imagej.ops.filter.pad.PadShiftKernelFFTMethods)2 FinalInterval (net.imglib2.FinalInterval)2 Interval (net.imglib2.Interval)2 Point (net.imglib2.Point)2 ArrayImgFactory (net.imglib2.img.array.ArrayImgFactory)2 IntType (net.imglib2.type.numeric.integer.IntType)2 FloatType (net.imglib2.type.numeric.real.FloatType)2 Before (org.junit.Before)2