private RandomAccessible<BitType> constantImg(final int numDims) { final long[] dims = new long[numDims]; Arrays.fill(dims, 1); final ArrayImg<BitType, LongArray> bitImg = ArrayImgs.bits(dims); bitImg.setLinkedType(new BitType(bitImg)); bitImg.cursor().next().set(true); return Views.extendBorder(bitImg); }
@Override public void run() { copy( b.array1.cursor(), new RandomAccessibleIntervalCursor< IntType >( b.array2 ) ); } } );
public static < T extends NativeType< T > & IntegerType< T > > void testRange( final ArrayImg< T, ? > comp, final ArrayImg< T, ? > ref, final int start, final int stop ) { final ArrayCursor< T > c = comp.cursor(); final ArrayCursor< T > r = ref.cursor(); for ( int s = start; s < stop; ++s ) { Assert.assertEquals( c.next().getInteger(), s ); Assert.assertEquals( r.next().getInteger(), s ); } }
@Test public void testDivideWithCursorExplicit() { final Cursor<FloatType> cursor = img1.cursor(); final Cursor<FloatType> cursorI = img2.cursor(); final Cursor<FloatType> cursorO = img3.cursor(); while (cursor.hasNext()) { cursor.fwd(); cursorI.fwd(); cursorO.fwd(); cursorO.get().set(cursorI.get()); cursorO.get().div(cursor.get()); } }
@Test public void testArrayCopy2() { copy( new RandomAccessibleIntervalCursor< IntType >( array1 ), array2.cursor() ); assertArrayEquals( intData, getImgAsInts( array2 ) ); }
@Test public void testCellCopy() { copy( array1.cursor(), new RandomAccessibleIntervalCursor< IntType >( cell ) ); assertArrayEquals( intData, getImgAsInts( cell ) ); } }
@Test public void testArrayCopy() { copy( array1.cursor(), new RandomAccessibleIntervalCursor< IntType >( array2 ) ); assertArrayEquals( intData, getImgAsInts( array2 ) ); }
/** * @param dim a long array with the desired dimensions of the image * @return an {@link Img} of {@link UnsignedByteType} filled with random * values. */ public Img<UnsignedByteType> getRandomUnsignedByteImg(final long[] dim) { final ArrayImg<UnsignedByteType, ByteArray> img = ArrayImgs.unsignedBytes( dim); final UnsignedByteType type = img.firstElement(); final ArrayCursor<UnsignedByteType> cursor = img.cursor(); while (cursor.hasNext()) { cursor.next().set(rand.nextInt((int) type.getMaxValue())); } return img; }
/** * @param dim a long array with the desired dimensions of the image * @param constValue constant image value * @return an {@link Img} of {@link UnsignedByteType} filled with a constant * value. */ public Img<UnsignedByteType> getConstantUnsignedByteImg(final long[] dim, final int constValue) { final ArrayImg<UnsignedByteType, ByteArray> img = ArrayImgs.unsignedBytes( dim); final UnsignedByteType type = img.firstElement(); if (constValue < type.getMinValue() || constValue >= type.getMaxValue()) { throw new IllegalArgumentException("Can't create image for constant [" + constValue + "]"); } final ArrayCursor<UnsignedByteType> cursor = img.cursor(); while (cursor.hasNext()) { cursor.next().set(constValue); } return img; }
@Test public void testXYCropping() { // selected interval XY final int[] xyAxis = new int[] { 0, 1 }; ops.run(SliceRAI2RAI.class, out, in, new DummyOp(), xyAxis); for (final Cursor<ByteType> cur = out.cursor(); cur.hasNext();) { cur.fwd(); assertEquals(cur.getIntPosition(2), cur.get().getRealDouble(), 0); } }
private void testXYZCropping(int t) { Img<ByteType> inSequence = ArrayImgs.bytes(20, 20, 21, t); ArrayImg<ByteType, ByteArray> outSequence = ArrayImgs.bytes(20, 20, 21, t); // fill array img with values (plane position = value in px); for (final Cursor<ByteType> cur = inSequence.cursor(); cur.hasNext();) { cur.fwd(); cur.get().set((byte) cur.getIntPosition(2)); } // selected interval XYZ final int[] xyAxis = new int[] { 0, 1, 2 }; ops.run(SliceRAI2RAI.class, outSequence, inSequence, new DummyOp(), xyAxis); for (final Cursor<ByteType> cur = outSequence.cursor(); cur.hasNext();) { cur.fwd(); assertEquals(cur.getIntPosition(2), cur.get().getRealDouble(), 0); } }
@Test public void testIdentity() { for ( int source = 0; source < numDimensions; ++source ) { for ( int target = 0; target < numDimensions; ++ target ) { if ( target == source ) continue; ShearTransform tf = new ShearTransform( numDimensions, target, source ); AbstractShearTransform iv = tf.inverse(); TransformView<FloatType> transformed = new TransformView< FloatType >( new TransformView< FloatType >( img, iv ), tf ); ArrayCursor<FloatType> i = img.cursor(); Cursor<FloatType> t = Views.flatIterable( Views.interval( transformed, img ) ).cursor(); while( t.hasNext() ) { Assert.assertTrue( i.hasNext() ); Assert.assertEquals( i.next().get(), t.next().get(), 0.0f ); } Assert.assertFalse( i.hasNext() ); } } }
@Test public void testJumpFwd() { final Cursor< IntType > c1 = array1.cursor(); final Cursor< IntType > c2 = new RandomAccessibleIntervalCursor< IntType >( array1 ); c1.fwd(); c2.fwd(); assertEquals( c1.get().get(), c2.get().get() ); for ( int i = 0; i < 10; ++i ) c1.fwd(); c2.jumpFwd( 10 ); assertEquals( c1.get().get(), c2.get().get() ); c1.jumpFwd( 713 ); c2.jumpFwd( 713 ); assertEquals( c1.get().get(), c2.get().get() ); }
for ( final Cursor< IntType > c = arrayImage.cursor(); c.hasNext(); )
for ( final Cursor< IntType > c = arrayImage.cursor(); c.hasNext(); )
for ( final Cursor< IntType > c = arrayImage.cursor(); c.hasNext(); )
for ( final Cursor< IntType > c = arrayImage.cursor(); c.hasNext(); )