Search in sources :

Example 86 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType in project imagej-ops by imagej.

the class UnaryRealTypeMathTest method assertRandomUniform.

private void assertRandomUniform(final double i, final double o, final long seed) {
    final DoubleType in = new DoubleType(i);
    final DoubleType out = (DoubleType) ops.run(RandomUniform.class, in.createVariable(), in, seed);
    assertEquals(o, out.get(), 0);
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) RandomUniform(net.imagej.ops.math.UnaryRealTypeMath.RandomUniform)

Example 87 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType in project imagej-ops by imagej.

the class StatisticsTest method MeanStdTest.

@Test
public void MeanStdTest() {
    float sum = 0.0f;
    for (int i = 0; i < arraySize; i++) {
        sum += array[i];
    }
    float variance = 0.0f;
    float mean1 = sum / (arraySize);
    // use the mean to calculate the variance
    for (int i = 0; i < arraySize; i++) {
        float temp = array[i] - mean1;
        variance += temp * temp;
    }
    variance = variance / arraySize;
    float std1 = (float) Math.sqrt(variance);
    // calculate mean using ops
    final DoubleType mean2 = new DoubleType();
    ops.run(IterableMean.class, mean2, img);
    // check that the ratio between mean1 and mean2 is 1.0
    Assert.assertEquals(1.0, mean1 / mean2.getRealFloat(), delta);
    // calculate standard deviation using ops
    final DoubleType std2 = new DoubleType();
    ops.run(IterableStandardDeviation.class, std2, img);
    // check that the ratio between std1 and std2 is 1.0
    Assert.assertEquals(1.0, std1 / std2.getRealFloat(), delta);
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 88 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType in project imagej-ops by imagej.

the class AddDimensionViewTest method addDimensionTest.

@Test
public void addDimensionTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
    MixedTransformView<DoubleType> il2 = Views.addDimension((RandomAccessible<DoubleType>) img);
    MixedTransformView<DoubleType> opr = ops.transform().addDimensionView((RandomAccessible<DoubleType>) img);
    assertEquals(il2.numDimensions(), opr.numDimensions());
    boolean[] il2Transform = new boolean[3];
    boolean[] oprTransform = new boolean[3];
    il2.getTransformToSource().getComponentZero(il2Transform);
    opr.getTransformToSource().getComponentZero(oprTransform);
    for (int i = 0; i < il2Transform.length; i++) {
        assertEquals(il2Transform[i], oprTransform[i]);
    }
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 89 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType in project imagej-ops by imagej.

the class AddDimensionViewTest method addDimensionMinMaxTest.

@Test
public void addDimensionMinMaxTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
    int max = 20;
    int min = 0;
    IntervalView<DoubleType> il2 = Views.addDimension(img, min, max);
    IntervalView<DoubleType> opr = ops.transform().addDimensionView(img, min, max);
    assertEquals(il2.numDimensions(), opr.numDimensions(), 0.0);
    for (int i = 0; i < il2.numDimensions(); i++) {
        assertEquals(il2.dimension(i), opr.dimension(i), 0.0);
    }
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 90 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType in project imagej-ops by imagej.

the class CollapseRealViewTest method defaultCollapseRealTest.

@Test
public void defaultCollapseRealTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
    CompositeIntervalView<DoubleType, RealComposite<DoubleType>> il2 = Views.collapseReal((RandomAccessibleInterval<DoubleType>) img);
    CompositeIntervalView<DoubleType, RealComposite<DoubleType>> opr = ops.transform().collapseRealView((RandomAccessibleInterval<DoubleType>) img);
    assertEquals(il2.numDimensions(), opr.numDimensions());
    CompositeView<DoubleType, RealComposite<DoubleType>> il2_2 = Views.collapseReal((RandomAccessible<DoubleType>) img, 1);
    CompositeView<DoubleType, RealComposite<DoubleType>> opr_2 = ops.transform().collapseRealView((RandomAccessible<DoubleType>) img, 1);
    assertEquals(il2_2.numDimensions(), opr_2.numDimensions());
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) RealComposite(net.imglib2.view.composite.RealComposite) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Aggregations

DoubleType (net.imglib2.type.numeric.real.DoubleType)142 Test (org.junit.Test)114 AbstractOpTest (net.imagej.ops.AbstractOpTest)104 LongType (net.imglib2.type.numeric.integer.LongType)37 Random (java.util.Random)19 Img (net.imglib2.img.Img)9 FinalInterval (net.imglib2.FinalInterval)8 ArrayList (java.util.ArrayList)7 Ops (net.imagej.ops.Ops)7 BitType (net.imglib2.type.logic.BitType)7 UnaryComputerOp (net.imagej.ops.special.computer.UnaryComputerOp)6 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)6 RealLocalizable (net.imglib2.RealLocalizable)6 LocalThresholdMethod (net.imagej.ops.threshold.LocalThresholdMethod)5 FinalDimensions (net.imglib2.FinalDimensions)5 CreateImgFromImg (net.imagej.ops.create.img.CreateImgFromImg)4 Dimensions (net.imglib2.Dimensions)4 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)4 Module (org.scijava.module.Module)4 CreateImgFromDimsAndType (net.imagej.ops.create.img.CreateImgFromDimsAndType)3