Search in sources :

Example 76 with ByteType

use of net.imglib2.type.numeric.integer.ByteType in project imagej-ops by imagej.

the class MapTest method testIIAndIIInplace.

@Test
public void testIIAndIIInplace() {
    final Img<ByteType> first = generateByteArrayTestImg(true, 10, 10);
    final Img<ByteType> firstCopy = first.copy();
    final Img<ByteType> second = generateByteArrayTestImg(false, 10, 10);
    for (final ByteType px : second) px.set((byte) 1);
    final Img<ByteType> secondCopy = second.copy();
    final Img<ByteType> secondDiffDims = generateByteArrayTestImg(false, 10, 10, 2);
    sub = Inplaces.binary(ops, Ops.Math.Subtract.class, ByteType.class);
    final BinaryInplaceOp<? super Img<ByteType>, Img<ByteType>> map = Inplaces.binary(ops, MapIIAndIIInplace.class, firstCopy, second, sub);
    map.run(firstCopy, second, firstCopy);
    map.run(first, secondCopy, secondCopy);
    assertImgSubEquals(first, second, firstCopy);
    assertImgSubEquals(first, second, secondCopy);
    // Expect exception when in2 has different dimensions
    thrown.expect(IllegalArgumentException.class);
    ops.op(MapIIAndIIInplace.class, first, secondDiffDims, sub);
}
Also used : Img(net.imglib2.img.Img) Ops(net.imagej.ops.Ops) ByteType(net.imglib2.type.numeric.integer.ByteType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 77 with ByteType

use of net.imglib2.type.numeric.integer.ByteType in project imagej-ops by imagej.

the class MapTest method testIterable.

@Test
public void testIterable() {
    final Img<ByteType> in = generateByteArrayTestImg(true, 10, 10);
    final Op nullary = Computers.nullary(ops, Ops.Math.Zero.class, ByteType.class);
    ops.run(MapNullaryIterable.class, in, nullary);
    for (final ByteType ps : in) assertEquals(ps.get(), 0);
}
Also used : Op(net.imagej.ops.Op) BinaryInplaceOp(net.imagej.ops.special.inplace.BinaryInplaceOp) ByteType(net.imglib2.type.numeric.integer.ByteType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 78 with ByteType

use of net.imglib2.type.numeric.integer.ByteType in project imagej-ops by imagej.

the class NonLinearFiltersTest method testVarianceFilter.

/**
 * @see VarianceFilterOp
 * @see DefaultVarianceFilter
 */
@Test
public void testVarianceFilter() {
    ops.run(VarianceFilterOp.class, out, in, shape, oobFactory);
    double sum = 0.0;
    double sumSq = 0.0;
    NeighborhoodsIterableInterval<ByteType> neighborhoods = shape.neighborhoods(Views.interval(Views.extendMirrorSingle(in), in));
    for (ByteType t : neighborhoods.firstElement()) {
        sum += t.getRealDouble();
        sumSq += t.getRealDouble() * t.getRealDouble();
    }
    assertEquals((byte) Util.round((sumSq - (sum * sum / 9)) / 8), out.firstElement().get());
}
Also used : ByteType(net.imglib2.type.numeric.integer.ByteType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 79 with ByteType

use of net.imglib2.type.numeric.integer.ByteType in project imagej-ops by imagej.

the class NonLinearFiltersTest method testMaxFilter.

/**
 * @see MaxFilterOp
 * @see DefaultMaxFilter
 */
@Test
public void testMaxFilter() {
    ops.run(MaxFilterOp.class, out, in, shape, oobFactory);
    byte max = Byte.MIN_VALUE;
    NeighborhoodsIterableInterval<ByteType> neighborhoods = shape.neighborhoods(Views.interval(Views.extendMirrorSingle(in), in));
    for (ByteType t : neighborhoods.firstElement()) {
        max = (byte) Math.max(t.getInteger(), max);
    }
    assertEquals(out.firstElement().get(), max);
}
Also used : ByteType(net.imglib2.type.numeric.integer.ByteType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 80 with ByteType

use of net.imglib2.type.numeric.integer.ByteType in project imagej-ops by imagej.

the class NonLinearFiltersTest method testMinFilter.

/**
 * @see MinFilterOp
 * @see DefaultMinFilter
 */
@Test
public void testMinFilter() {
    ops.run(MinFilterOp.class, out, in, shape, oobFactory);
    byte min = Byte.MAX_VALUE;
    NeighborhoodsIterableInterval<ByteType> neighborhoods = shape.neighborhoods(Views.interval(Views.extendMirrorSingle(in), in));
    for (ByteType t : neighborhoods.firstElement()) {
        min = (byte) Math.min(t.getInteger(), min);
    }
    assertEquals(min, out.firstElement().get());
}
Also used : ByteType(net.imglib2.type.numeric.integer.ByteType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Aggregations

ByteType (net.imglib2.type.numeric.integer.ByteType)83 Test (org.junit.Test)78 AbstractOpTest (net.imagej.ops.AbstractOpTest)76 RectangleShape (net.imglib2.algorithm.neighborhood.RectangleShape)55 Img (net.imglib2.img.Img)49 ArrayImg (net.imglib2.img.array.ArrayImg)33 Shape (net.imglib2.algorithm.neighborhood.Shape)18 DiamondShape (net.imglib2.algorithm.neighborhood.DiamondShape)17 HorizontalLineShape (net.imglib2.algorithm.neighborhood.HorizontalLineShape)16 ArrayList (java.util.ArrayList)9 Op (net.imagej.ops.Op)9 IterableInterval (net.imglib2.IterableInterval)9 BitType (net.imglib2.type.logic.BitType)6 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)6 AbstractUnaryComputerOp (net.imagej.ops.special.computer.AbstractUnaryComputerOp)5 Ops (net.imagej.ops.Ops)4 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)4 IncompatibleTypeException (net.imglib2.exception.IncompatibleTypeException)4 CreateImgFromImg (net.imagej.ops.create.img.CreateImgFromImg)3 MapOp (net.imagej.ops.map.MapOp)3