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 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 IterableIntervalPointSetIterator() { super(interval.numDimensions()); cursor = interval.localizingCursor(); pos = new long[n]; }
public IterableIntervalPointSet(IterableInterval<?> interval) { this.interval = interval; int numDims = interval.numDimensions(); this.boundMin = new long[numDims]; this.boundMax = new long[numDims]; interval.min(boundMin); interval.max(boundMax); long sum = 1; for (int i = 0; i < numDims; i++) { sum *= 1 + boundMax[i] - boundMin[i]; } this.size = sum; }
private Paste(final RI source, final IterableInterval<Y> target, final long[] offset) { this.target = target; this.tc = target.cursor(); this.min = new long[source.numDimensions()]; this.max = new long[source.numDimensions()]; for (int i=0; i<this.min.length; ++i) { this.min[i] = (long) Math.min(offset[i], target.realMax(i)); this.max[i] = (long) Math.min(offset[i] + source.realMax(i), target.realMax(i)); } RandomAccessibleInterval<T> view = Views.interval(source, min, max); this.copier = source.iterationOrder().equals(target.iterationOrder()) ? new CompatibleCopier(view) : new RandomAccessCopier(view); }
public static <I, O> void map(final RandomAccessibleInterval<I> a, final IterableInterval<O> b, final UnaryComputerOp<I, O> op) { final RandomAccess<I> aAccess = a.randomAccess(); final Cursor<O> bCursor = b.localizingCursor(); while (bCursor.hasNext()) { bCursor.fwd(); aAccess.setPosition(bCursor); op.compute(aAccess.get(), bCursor.get()); } }
min[ d ] = max[ d ] = position[ d ]; min[ dimX ] = target.min( 0 ); min[ dimY ] = target.min( 1 ); max[ dimX ] = target.max( 0 ); max[ dimY ] = target.max( 1 ); final IterableInterval< A > ii = Views.iterable( Views.interval( source, new FinalInterval( min, max ) ) ); final Cursor< A > sourceCursor = ii.cursor(); if ( target.iterationOrder().equals( ii.iterationOrder() ) && !( sourceCursor instanceof RandomAccessibleIntervalCursor ) ) final Cursor< B > targetCursor = target.cursor(); while ( targetCursor.hasNext() ) else if ( target.iterationOrder() instanceof FlatIterationOrder ) final Cursor< B > targetCursor = target.cursor(); targetCursor.fwd(); final FinalInterval sourceInterval = new FinalInterval( min, max ); final long cr = -target.dimension( 0 ); final long width = target.dimension( 0 ); final long height = target.dimension( 1 ); final Cursor< B > targetCursor = target.localizingCursor();
Img< T > avgPSF = imgFactory.create( maxSize, Views.iterable( imgs.iterator().next() ).firstElement() ); if ( Views.isZeroMin( psfIn ) ) psf = Views.iterable( psfIn ); else psf = Views.iterable( Views.zeroMin( psfIn ) ); final RandomAccess< T > avgCursor = Views.extendZero( avgPSF ).randomAccess(); final Cursor< T > psfCursor = psf.localizingCursor(); psfCenter[ d ] = psf.dimension( d ) / 2; while ( psfCursor.hasNext() ) psfCursor.fwd(); psfCursor.localize( loc ); avgCursor.setPosition( loc ); avgCursor.get().add( psfCursor.get() ); type.setReal( type.getRealDouble() / (double)imgs.size() );
min[ d ] = max[ d ] = position[ d ]; min[ 0 ] = target.min( 0 ); min[ 1 ] = target.min( 1 ); max[ 0 ] = target.max( 0 ); max[ 1 ] = target.max( 1 ); final IterableInterval< A > srcIterable = Views.iterable( Views.interval( source, new FinalInterval( min, max ) ) ); final Cursor< B > targetCursor = target.localizingCursor(); if ( target.iterationOrder().equals( srcIterable.iterationOrder() ) ) final Cursor< A > sourceCursor = srcIterable.cursor(); while ( targetCursor.hasNext() ) converter.convert( sourceCursor.next(), targetCursor.next() ); final B b = targetCursor.next(); sourceRandomAccess.setPosition( targetCursor.getLongPosition( 0 ), 0 ); sourceRandomAccess.setPosition( targetCursor.getLongPosition( 1 ), 1 ); converter.convert( sourceRandomAccess.get(), b );
Cursor< T > cursor = input.cursor(); m_min = cursor.get().getMaxValue(); m_max = cursor.get().getMinValue(); while ( cursor.hasNext() ) cursor.fwd(); m_max = Math.max( m_max, cursor.get().getRealDouble() ); m_min = Math.min( m_min, cursor.get().getRealDouble() ); cursor = input.localizingCursor(); m_pixels = new int[ ( int ) input.dimension( m_dimY ) ][ ( int ) input.dimension( m_dimX ) ]; cursor.fwd(); m_pixels[ cursor.getIntPosition( m_dimY ) - ( int ) input.min( m_dimY ) ][ cursor.getIntPosition( m_dimX ) - ( int ) input.min( m_dimX ) ] = ( int ) ( ( ( cursor.get().getRealDouble() - m_min ) / ( m_max - m_min + 1 ) ) * m_nrGrayLevels );
/** * 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; }
/** * 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 <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; }
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 <T extends RealType<T>> String ascii( final IterableInterval<T> image, final T min, final T max) final long dim0 = image.dimension(0); final long dim1 = image.dimension(1); final T span = max.copy(); span.sub(min); final Cursor<T> cursor = image.localizingCursor(); final int[] pos = new int[image.numDimensions()]; final T tmp = image.firstElement().copy(); while (cursor.hasNext()) { cursor.fwd(); cursor.localize(pos); final int index = w * pos[1] + pos[0];
final Cursor<? extends RealType<?>> cursor = input.localizingCursor(); final double localMin = minMax.getA().getRealDouble(); final double localMax = minMax.getB().getRealDouble(); final int[][] pixels = new int[(int) input.dimension(1)][(int) input .dimension(0)]; final int minimumX = (int) input.min(0); final int minimumY = (int) input.min(1); final double diff = localMax - localMin; while (cursor.hasNext()) { cursor.fwd(); final int bin = (int) (((cursor.get().getRealDouble() - localMin) / diff) * (nrGreyLevels)); pixels[cursor.getIntPosition(1) - minimumY][cursor.getIntPosition(0) -
private static < T extends RealType< T >, U extends RealType< U > > void transformL1AlongDimension( final RandomAccessible< T > source, final RandomAccessibleInterval< U > target, final int dim, final double weight ) { final int lastDim = target.numDimensions() - 1; final long size = target.dimension( dim ); final RealComposite< DoubleType > tmp = Views.collapseReal( createAppropriateOneDimensionalImage( size, new DoubleType() ) ).randomAccess().get(); // do not permute if we already work on last dimension final Cursor< RealComposite< T > > s = Views.flatIterable( Views.collapseReal( dim == lastDim ? Views.interval( source, target ) : Views.permute( Views.interval( source, target ), dim, lastDim ) ) ).cursor(); final Cursor< RealComposite< U > > t = Views.flatIterable( Views.collapseReal( dim == lastDim ? target : Views.permute( target, dim, lastDim ) ) ).cursor(); while ( s.hasNext() ) { final RealComposite< T > sourceComp = s.next(); final RealComposite< U > targetComp = t.next(); for ( long i = 0; i < size; ++i ) { tmp.get( i ).set( sourceComp.get( i ).getRealDouble() ); } transformL1SingleColumn( tmp, targetComp, weight, size ); } }
@Override public void compute(final IterableInterval<I> input, final O output) { double moment00 = 0; final Cursor<I> cur = input.localizingCursor(); while (cur.hasNext()) { cur.fwd(); double val = cur.get().getRealDouble(); moment00 += val; } output.setReal(moment00); } }
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; }