Search in sources :

Example 1 with CompositeView

use of net.imglib2.view.composite.CompositeView in project imagej-ops by imagej.

the class PartialDerivativeFilterTest method testAllDerivatives.

@Test
public void testAllDerivatives() {
    Img<FloatType> img = generateFloatArrayTestImg(false, new long[] { 20, 20, 3 });
    Cursor<FloatType> cursorImg = img.cursor();
    int counterX = 0;
    int counterY = 0;
    while (cursorImg.hasNext()) {
        if (counterX > 8 && counterX < 12 || counterY > 8 && counterY < 12) {
            cursorImg.next().setOne();
        } else {
            cursorImg.next().setZero();
        }
        counterX++;
        if (counterX % 20 == 0) {
            counterY++;
        }
        if (counterX == 20) {
            counterX = 0;
        }
        if (counterY == 20) {
            counterY = 0;
        }
    }
    CompositeIntervalView<FloatType, RealComposite<FloatType>> out = ops.filter().allPartialDerivatives(img);
    CompositeView<FloatType, RealComposite<FloatType>>.CompositeRandomAccess outRA = out.randomAccess();
    FloatType type = Util.getTypeFromInterval(img).createVariable();
    // position 9,8 in all dimensions
    outRA.setPosition(new int[] { 9, 8, 0 });
    RealComposite<FloatType> outvalue = outRA.get();
    Float[] correctValues = new Float[] { 12.0f, 4.0f, 0.0f };
    int i = 0;
    for (FloatType value : outvalue) {
        type.set(correctValues[i]);
        assertEquals(type, value);
        i++;
    }
    outRA.setPosition(new int[] { 9, 8, 1 });
    outvalue = outRA.get();
    correctValues = new Float[] { 12.0f, 4.0f, 0.0f };
    i = 0;
    for (FloatType value : outvalue) {
        type.set(correctValues[i]);
        assertEquals(type, value);
        i++;
    }
    outRA.setPosition(new int[] { 9, 8, 2 });
    outvalue = outRA.get();
    correctValues = new Float[] { 12.0f, 4.0f, 0.0f };
    i = 0;
    for (FloatType value : outvalue) {
        type.set(correctValues[i]);
        assertEquals(type, value);
        i++;
    }
    // position 9,9 in all dimensions
    outRA.setPosition(new int[] { 9, 9, 0 });
    outvalue = outRA.get();
    correctValues = new Float[] { 4.0f, 4.0f, 0.0f };
    i = 0;
    for (FloatType value : outvalue) {
        type.set(correctValues[i]);
        assertEquals(type, value);
        i++;
    }
    outRA.setPosition(new int[] { 9, 9, 1 });
    outvalue = outRA.get();
    correctValues = new Float[] { 4.0f, 4.0f, 0.0f };
    i = 0;
    for (FloatType value : outvalue) {
        type.set(correctValues[i]);
        assertEquals(type, value);
        i++;
    }
    outRA.setPosition(new int[] { 9, 9, 2 });
    outvalue = outRA.get();
    correctValues = new Float[] { 4.0f, 4.0f, 0.0f };
    i = 0;
    for (FloatType value : outvalue) {
        type.set(correctValues[i]);
        assertEquals(type, value);
        i++;
    }
    // position 9,10 in all dimensions
    outRA.setPosition(new int[] { 9, 10, 0 });
    outvalue = outRA.get();
    correctValues = new Float[] { 0.0f, 0.0f, 0.0f };
    i = 0;
    for (FloatType value : outvalue) {
        type.set(correctValues[i]);
        assertEquals(type, value);
        i++;
    }
    outRA.setPosition(new int[] { 9, 10, 1 });
    outvalue = outRA.get();
    correctValues = new Float[] { 0.0f, 0.0f, 0.0f };
    i = 0;
    for (FloatType value : outvalue) {
        type.set(correctValues[i]);
        assertEquals(type, value);
        i++;
    }
    outRA.setPosition(new int[] { 9, 10, 2 });
    outvalue = outRA.get();
    correctValues = new Float[] { 0.0f, 0.0f, 0.0f };
    i = 0;
    for (FloatType value : outvalue) {
        type.set(correctValues[i]);
        assertEquals(type, value);
        i++;
    }
    // position 9,11 in all dimensions
    outRA.setPosition(new int[] { 9, 11, 0 });
    outvalue = outRA.get();
    correctValues = new Float[] { 4.0f, -4.0f, 0.0f };
    i = 0;
    for (FloatType value : outvalue) {
        type.set(correctValues[i]);
        assertEquals(type, value);
        i++;
    }
    outRA.setPosition(new int[] { 9, 11, 1 });
    outvalue = outRA.get();
    correctValues = new Float[] { 4.0f, -4.0f, 0.0f };
    i = 0;
    for (FloatType value : outvalue) {
        type.set(correctValues[i]);
        assertEquals(type, value);
        i++;
    }
    outRA.setPosition(new int[] { 9, 11, 2 });
    outvalue = outRA.get();
    correctValues = new Float[] { 4.0f, -4.0f, 0.0f };
    i = 0;
    for (FloatType value : outvalue) {
        type.set(correctValues[i]);
        assertEquals(type, value);
        i++;
    }
}
Also used : CompositeView(net.imglib2.view.composite.CompositeView) RealComposite(net.imglib2.view.composite.RealComposite) FloatType(net.imglib2.type.numeric.real.FloatType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 2 with CompositeView

use of net.imglib2.view.composite.CompositeView in project imagej-ops by imagej.

the class CollapseNumericViewTest method defaultCollapseNumericTest.

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

Example 3 with CompositeView

use of net.imglib2.view.composite.CompositeView 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)

Example 4 with CompositeView

use of net.imglib2.view.composite.CompositeView in project imagej-ops by imagej.

the class CollapseViewTest method collapseRATest.

@Test
public void collapseRATest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10, 10 }, new DoubleType());
    CompositeView<DoubleType, ? extends GenericComposite<DoubleType>> il2 = Views.collapse((RandomAccessible<DoubleType>) img);
    CompositeView<DoubleType, ? extends GenericComposite<DoubleType>> opr = ops.transform().collapseView((RandomAccessible<DoubleType>) img);
    assertEquals(il2.numDimensions(), opr.numDimensions());
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 5 with CompositeView

use of net.imglib2.view.composite.CompositeView in project imagej-ops by imagej.

the class HessianFilterTest method test.

@Test
public void test() {
    Img<FloatType> img = generateFloatArrayTestImg(false, new long[] { 50, 50 });
    Cursor<FloatType> cursorImg = img.cursor();
    int counterX = 0;
    int counterY = 0;
    while (cursorImg.hasNext()) {
        if (counterX > 20 && counterX < 30 || counterY > 20 && counterY < 30) {
            cursorImg.next().setOne();
        } else {
            cursorImg.next().setZero();
        }
        counterX++;
        if (counterX % 50 == 0) {
            counterY++;
        }
        if (counterX == 50) {
            counterX = 0;
        }
        if (counterY == 50) {
            counterY = 0;
        }
    }
    CompositeIntervalView<FloatType, RealComposite<FloatType>> out = ops.filter().hessian(img);
    Cursor<RealComposite<FloatType>> outCursor = Views.iterable(out).cursor();
    while (outCursor.hasNext()) {
        RealComposite<FloatType> values = outCursor.next();
        assertEquals(values.get(1), values.get(2));
    }
    CompositeView<FloatType, RealComposite<FloatType>>.CompositeRandomAccess outRA = out.randomAccess();
    // two numbers represent a coordinate: 20|0 ; 21|0 ...
    int[] positions = new int[] { 20, 0, 21, 0, 19, 31, 19, 30 };
    float[] valuesXX = new float[] { 16.0f, -16.0f, 15.0f, 11.0f };
    float[] valuesXY = new float[] { 0.0f, 0.0f, 1.0f, 3.0f };
    float[] valuesYY = new float[] { 0.0f, 0.0f, 15.0f, 15.0f };
    FloatType type = Util.getTypeFromInterval(img).createVariable();
    int i = 0;
    int j = 0;
    while (i < positions.length - 1) {
        int[] pos = new int[2];
        pos[0] = positions[i];
        pos[1] = positions[i + 1];
        outRA.setPosition(pos);
        type.set(valuesXX[j]);
        assertEquals(type, outRA.get().get(0));
        outRA.setPosition(pos);
        type.set(valuesXY[j]);
        assertEquals(type, outRA.get().get(1));
        outRA.setPosition(pos);
        type.set(valuesYY[j]);
        assertEquals(type, outRA.get().get(3));
        i += 2;
        j++;
    }
}
Also used : CompositeView(net.imglib2.view.composite.CompositeView) RealComposite(net.imglib2.view.composite.RealComposite) FloatType(net.imglib2.type.numeric.real.FloatType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Aggregations

AbstractOpTest (net.imagej.ops.AbstractOpTest)5 Test (org.junit.Test)5 RealComposite (net.imglib2.view.composite.RealComposite)3 DoubleType (net.imglib2.type.numeric.real.DoubleType)2 FloatType (net.imglib2.type.numeric.real.FloatType)2 CompositeView (net.imglib2.view.composite.CompositeView)2 NativeARGBDoubleType (net.imglib2.type.numeric.NativeARGBDoubleType)1 NumericComposite (net.imglib2.view.composite.NumericComposite)1