public static <I1, I2, O extends I1> void inplace( final IterableInterval<O> arg, final RandomAccessibleInterval<I2> in, final BinaryInplace1Op<I1, I2, O> op) { final Cursor<O> argCursor = arg.localizingCursor(); final RandomAccess<I2> inAccess = in.randomAccess(); while (argCursor.hasNext()) { argCursor.fwd(); inAccess.setPosition(argCursor); op.mutate1(argCursor.get(), inAccess.get()); } }
public static <I1, I2, O> void map(final IterableInterval<I1> a, final IterableInterval<I2> b, final RandomAccessibleInterval<O> c, final BinaryComputerOp<I1, I2, O> op) { final Cursor<I1> aCursor = a.localizingCursor(); final Cursor<I2> bCursor = b.cursor(); final RandomAccess<O> cAccess = c.randomAccess(); while (aCursor.hasNext()) { aCursor.fwd(); cAccess.setPosition(aCursor); op.compute(aCursor.get(), bCursor.next(), cAccess.get()); } }
public static < T extends RealType< T > > void subtractProjection( final RandomAccessibleInterval< T > img, final RandomAccessibleInterval< T > proj, final int projDim ) { final int n0 = img.numDimensions(); final Cursor< T > cursor = Views.iterable( img ).localizingCursor(); final RandomAccess< T > ra = proj.randomAccess(); while ( cursor.hasNext() ) { final T type = cursor.next(); int dim = 0; for ( int d = 0; d < n0; ++d ) if ( d != projDim ) ra.setPosition( cursor.getLongPosition( d ), dim++ ); type.sub( ra.get() ); } }
public static final < T extends RealType< T > > void readBytes( final byte[] b, final Cursor< T > cursor, final int width ) { while( cursor.hasNext() ) { cursor.fwd(); // otherwise the position is off below cursor.get().setReal( b[ cursor.getIntPosition( 0 ) + cursor.getIntPosition( 1 ) * width ] & 0xff ); } }
public void copyWithSourceIteration( final Img< IntType > srcImg, final Img< IntType > dstImg ) { final int[] pos = new int[ dimensions.length ]; final Cursor< IntType > src = srcImg.localizingCursor(); final RandomAccess< IntType > dst = dstImg.randomAccess(); while ( src.hasNext() ) { src.fwd(); src.localize( pos ); dst.setPosition( pos ); dst.get().set( src.get() ); } }
@Override public void compute(final IterableInterval<I> input, final O output) { double moment01 = 0; final Cursor<I> cur = input.localizingCursor(); while (cur.hasNext()) { cur.fwd(); double y = cur.getDoublePosition(1); double val = cur.get().getRealDouble(); moment01 += y * val; } output.setReal(moment01); } }
/** * Runs the operation. This operation fills the whole output image region * with the binary combination of the input values. The output region must be * contained within the extents of each of the input regions. */ @Override public RandomAccessibleInterval<W> compute(RandomAccessibleInterval<U> input1, RandomAccessibleInterval<V> input2, RandomAccessibleInterval<W> output) { long[] position = new long[output.numDimensions()]; Cursor<W> cursor = Views.iterable( output ).localizingCursor(); RandomAccess<U> accessor1 = input1.randomAccess(); RandomAccess<V> accessor2 = input2.randomAccess(); while (cursor.hasNext()) { cursor.fwd(); cursor.localize(position); accessor1.setPosition(position); accessor2.setPosition(position); operation.compute(accessor1.get(), accessor2.get(), cursor.get()); } return output; }
public static final <T extends RealType<T>> void addGaussianNoiseToImage(Img<T> img, double sigma_noise) { Cursor<T> lc = img.localizingCursor(); double val; T var = img.firstElement().createVariable(); while (lc.hasNext()) { lc.fwd(); val = Math.max(0, sigma_noise * ran.nextGaussian()); var.setReal(val); lc.get().add(var); } }
/** * copy src to dest * @param src : source, will not be modified * @param dest : destiantion, will be modified * @param <T> pixel type source * @param <S> pixel type destination */ public static <T extends RealType<T>, S extends RealType<S>> void copy(RandomAccessible< T > src, RandomAccessibleInterval< S > dest) { final Cursor< S > destCursor = Views.iterable( dest ).localizingCursor(); final RandomAccess< T > srcRA = src.randomAccess(); while (destCursor.hasNext()) { destCursor.fwd(); srcRA.setPosition( destCursor ); destCursor.get().setReal( srcRA.get().getRealDouble() ); } }
public static <I, O> void map(final RandomAccessibleInterval<I> a, final IterableInterval<O> b, final UnaryComputerOp<I, O> op, final long startIndex, final long stepSize, final long numSteps) { if (numSteps <= 0) return; final RandomAccess<I> aAccess = a.randomAccess(); final Cursor<O> bCursor = b.localizingCursor(); for (long ctr = 0; ctr < numSteps; ctr++) { bCursor.jumpFwd(ctr == 0 ? startIndex + 1 : stepSize); aAccess.setPosition(bCursor); op.compute(aAccess.get(), bCursor.get()); } }
public static <P extends RealType< P >, Q extends RealType< Q >> double getMeanCorrected(RandomAccessibleInterval< P > brightImg, RandomAccessibleInterval< Q > darkImg) { final RealSum sum = new RealSum(); long count = 0; final Cursor< P > brightCursor = Views.iterable( brightImg ).cursor(); final RandomAccess< Q > darkRA = darkImg.randomAccess(); while (brightCursor.hasNext()) { brightCursor.fwd(); darkRA.setPosition( brightCursor ); sum.add( brightCursor.get().getRealDouble() - darkRA.get().getRealDouble()); count++; } if (count == 0) return 0.0; else return sum.getSum() / count; }
@Test public void testCopy() { ops.run(ConvertIIs.class, out, in, new CopyRealTypes<ShortType, ByteType>()); final Cursor<ShortType> c = in.localizingCursor(); final RandomAccess<ByteType> ra = out.randomAccess(); while (c.hasNext()) { final short value = c.next().get(); ra.setPosition(c); assertEquals(copy(value), ra.get().get()); } }
protected void mapSingle( final RandomAccess< A > sourceRandomAccess, final Converter< A, ARGBType > conv ) { final Cursor< ARGBType > targetCursor = target.localizingCursor(); while ( targetCursor.hasNext() ) { targetCursor.fwd(); sourceRandomAccess.setPosition( targetCursor.getLongPosition( 0 ), 0 ); sourceRandomAccess.setPosition( targetCursor.getLongPosition( 1 ), 1 ); conv.convert( sourceRandomAccess.get(), targetCursor.get() ); } } }
@Test public void defaultPermuteCoordinatesTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{2, 2}, new DoubleType()); Cursor<DoubleType> c = img.cursor(); MersenneTwisterFast r = new MersenneTwisterFast(SEED); while (c.hasNext()) { c.next().set(r.nextDouble()); } Cursor<DoubleType> il2 = Views.permuteCoordinates(img, new int[]{0, 1}).cursor(); RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesView(img, new int[]{0, 1}).randomAccess(); while (il2.hasNext()) { il2.next(); opr.setPosition(il2); assertEquals(il2.get().get(), opr.get().get(), 1e-10); } }
public static final < T extends RealType< T >> void addGaussianNoiseToImage( RandomAccessibleInterval< T > img, double sigma_noise ) { IterableInterval< T > iterImg = Views.iterable( img ); Cursor< T > lc = iterImg.localizingCursor(); double val; T var = iterImg.firstElement().createVariable(); while ( lc.hasNext() ) { lc.fwd(); val = Math.max( 0, sigma_noise * ran.nextGaussian() ); var.setReal( val ); lc.get().add( var ); } }
public <T extends RealType<T>> boolean areCongruent( final IterableInterval<T> in, final RandomAccessible<T> out, final double epsilon) { Cursor<T> cin = in.localizingCursor(); RandomAccess<T> raOut = out.randomAccess(); while (cin.hasNext()) { cin.fwd(); raOut.setPosition(cin); if (Math.abs(cin.get().getRealDouble() - raOut.get() .getRealDouble()) > epsilon) return false; } return true; }
@Test public void testNormalizeScale() { ops.run(ConvertIIs.class, out, in, ops.op(NormalizeScaleRealTypes.class, out.firstElement(), in.firstElement())); final Cursor<ShortType> c = in.localizingCursor(); final RandomAccess<ByteType> ra = out.randomAccess(); while (c.hasNext()) { final short value = c.next().get(); ra.setPosition(c); assertEquals(normalizeScale(value), ra.get().get()); } }
@Override public Void call() throws Exception { final Cursor< UnsignedShortType > in = Views.iterable( ushortImg ).localizingCursor(); final RandomAccess< FloatType > out = floatImg.randomAccess(); in.jumpFwd( startPosition ); for ( long j = 0; j < loopSize; ++j ) { final UnsignedShortType vin = in.next(); out.setPosition( in ); out.get().set( vin.getRealFloat() ); } return null; } } );