Refine search
/** * 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 < T extends RealType< T > > double[] minMaxApprox( final RandomAccessibleInterval< T > img, final Random rnd, final int numPixels ) { final RandomAccess< T > ra = img.randomAccess(); // run threads and combine results double min = Double.MAX_VALUE; double max = -Double.MAX_VALUE; for ( int i = 0; i < numPixels; ++i ) { for ( int d = 0; d < img.numDimensions(); ++d ) ra.setPosition( rnd.nextInt( (int)img.dimension( d ) ) + (int)img.min( d ), d ); final double v = ra.get().getRealDouble(); min = Math.min( min, v ); max = Math.max( max, v ); } return new double[]{ min, max }; }
@SuppressWarnings( "unchecked" ) public StackView( final List< ? extends RandomAccessibleInterval< T > > hyperslices, final StackAccessMode stackAccessMode ) { super( hyperslices.get( 0 ).numDimensions() + 1 ); this.stackAccessMode = stackAccessMode; slices = hyperslices.toArray( new RandomAccessibleInterval[ hyperslices.size() ] ); for ( int d = 0; d < n - 1; ++d ) { min[ d ] = slices[ 0 ].min( d ); max[ d ] = slices[ 0 ].max( d ); } min[ n - 1 ] = 0; max[ n - 1 ] = slices.length - 1; }
public Bandpass( final RandomAccessibleInterval< T > input, final int beginRadius, final int endRadius, ImgFactory<T> imgFactory ) { this.input = input; this.inPlace = false; this.bandPass = true; this.beginRadius = beginRadius; this.endRadius = endRadius; this.origin = new long[ input.numDimensions() ]; this.origin[ 0 ] = input.dimension( 0 ) - 1; for ( int d = 1; d < this.origin.length; ++d ) origin[ d ] = input.dimension( d ) / 2; }
public Phase1Runnable3D(final int[][][] tempValues, final RandomAccessibleInterval<B> raIn, final int yPos, final int zPos) { this.tempValues = tempValues; this.raIn = raIn.randomAccess(); this.y = yPos; this.z = zPos; this.infinite = (int) (raIn.dimension(0) + raIn.dimension(1)); this.width = (int) raIn.dimension(0); }
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()); } }
private void copy(final RandomAccessibleInterval<BitType> source, final RandomAccessibleInterval<BitType> target) { final IterableInterval<BitType> targetIt = Views.iterable(target); final IterableInterval<BitType> sourceIt = Views.iterable(source); if (sourceIt.iterationOrder().equals(targetIt.iterationOrder())) { final Cursor<BitType> targetCursor = targetIt.cursor(); final Cursor<BitType> sourceCursor = sourceIt.cursor(); while (sourceCursor.hasNext()) { targetCursor.fwd(); sourceCursor.fwd(); targetCursor.get().set(sourceCursor.get().get()); } } else { // Fallback to random access final RandomAccess<BitType> targetRA = target.randomAccess(); final Cursor<BitType> sourceCursor = sourceIt.localizingCursor(); while (sourceCursor.hasNext()) { sourceCursor.fwd(); targetRA.setPosition(sourceCursor); targetRA.get().set(sourceCursor.get().get()); } } }
private RandomAccessibleInterval<T> project( final RandomAccessibleInterval<T> image) if (image.numDimensions() < 2) { throw new IllegalArgumentException("Dimensionality too small: " + // image.numDimensions()); final IterableInterval<T> input = Views.iterable(image); final T type = input.firstElement(); // e.g. unsigned 8-bit final long xLen = image.dimension(0); final long yLen = image.dimension(1); final Img<T> output = new ArrayImgFactory<T>().create(outputDims, type); for (final T sample : output) { sample.setReal(type.getMinValue()); final Cursor<T> inPos = input.localizingCursor(); final RandomAccess<T> outPos = output.randomAccess(); while (inPos.hasNext()) { final T inPix = inPos.next(); final long xPos = inPos.getLongPosition(0); final long yPos = inPos.getLongPosition(1); outPos.setPosition(xPos, 0); outPos.setPosition(yPos, 1); final T outPix = outPos.get(); if (outPix.compareTo(inPix) < 0) { outPix.set(inPix);
public static final < T extends RealType< T >> void addGaussianSpotToImage( RandomAccessibleInterval< T > img, double[] params ) { IterableInterval< T > iterImg = Views.iterable( img ); Cursor< T > lc = iterImg.localizingCursor(); int nDims = img.numDimensions(); double[] position = new double[ nDims ]; double val; T var = iterImg.firstElement().createVariable(); while ( lc.hasNext() ) { lc.fwd(); lc.localize( position ); val = gaussian.val( position, params ); var.setReal( val ); lc.get().add( var ); } }
public static Pair< FloatProcessor, FloatProcessor > getTwoImagesA( final Img< FloatType > imgIn, final int z, final int dist ) { final RandomAccessible< FloatType > r = Views.extendMirrorSingle( imgIn ); final RandomAccessibleInterval< FloatType > img = Views.interval( r, imgIn ); final RandomAccessibleInterval< FloatType > s0 = Views.hyperSlice( img, 2, z ); final RandomAccessibleInterval< FloatType > s1 = Views.hyperSlice( img, 2, z + dist ); final FloatProcessor fp0 = new FloatProcessor( (int)s0.dimension( 0 ), (int)s0.dimension( 1 ) ); final FloatProcessor fp1 = new FloatProcessor( (int)s0.dimension( 0 ), (int)s0.dimension( 1 ) ); final Cursor< FloatType > c0 = Views.iterable( s0 ).localizingCursor(); final Cursor< FloatType > c1 = Views.iterable( s1 ).localizingCursor(); while ( c0.hasNext() ) { c0.fwd(); c1.fwd(); fp0.setf( c0.getIntPosition( 0 ), c0.getIntPosition( 1 ), c0.get().get() ); fp1.setf( c1.getIntPosition( 0 ), c1.getIntPosition( 1 ), c1.get().get() ); } return new ValuePair< FloatProcessor, FloatProcessor >( fp0, fp1 ); }
final RandomAccessibleInterval< T > target ) final IterableInterval< T > sourceIterable = Views.iterable( source ); final IterableInterval< T > targetIterable = Views.iterable( target ); if ( sourceIterable.iterationOrder().equals( targetIterable.iterationOrder() ) ) final Cursor< T > cursorSource = sourceIterable.cursor(); final Cursor< T > cursorTarget = targetIterable.cursor(); cursorSource.jumpFwd( start ); cursorTarget.jumpFwd( start ); cursorTarget.next().set( cursorSource.next() ); final RandomAccess< T > raSource = source.randomAccess(); final Cursor< T > cursorTarget = targetIterable.localizingCursor(); cursorTarget.fwd(); raSource.setPosition( cursorTarget ); cursorTarget.get().set( raSource.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 <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; }
final Cursor<T> cursor = Views.iterable(input).localizingCursor(); final OutOfBoundsMirrorFactory<T, RandomAccessibleInterval<T>> osmf = new OutOfBoundsMirrorFactory<>(Boundary.SINGLE); final RandomAccess<T> inputRA = osmf.create(input); final RandomAccess<DoubleType> outputRA = output.randomAccess(); while (cursor.hasNext()) { cursor.fwd(); inputRA.setPosition(cursor); outputRA.setPosition(cursor); sum = 0; inputRA.setPosition(cursor.getLongPosition(0) + i, 0); inputRA.setPosition(cursor.getLongPosition(1), 1); sum += inputRA.get().getRealDouble() * mask[i + halfWidth]; outputRA.get().setReal(sum);
@Override public void run() { Cursor<FloatType> incrementCursor = increment.localizingCursor(); RandomAccess<T> ra = image.randomAccess(); float val, inc, sum; incrementCursor.reset(); incrementCursor.jumpFwd(chunk.getStartPosition()); for (long j = 0; j < chunk.getLoopSize(); j++) { inc = incrementCursor.next().get(); // FloatType, might be negative ra.setPosition(incrementCursor); val = ra.get().getRealFloat(); // T type, might be 0 // Over/Underflow protection sum = val + inc; if (sum > maxVal) { sum = maxVal; } if (sum < minVal) { sum = minVal; } ra.get().setReal(sum); } } };
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()); } }
private static final void copy( final long start, final long loopSize, final RandomAccessible< FloatType > source, final RandomAccessibleInterval< FloatType > block, final long[] offset ) { final int numDimensions = source.numDimensions(); final Cursor< FloatType > cursor = Views.iterable( block ).localizingCursor(); // define where we will query the RandomAccess on the source // (we say it is the entire block, although it is just a part of it, // but which part depends on the underlying container) final long[] min = new long[ numDimensions ]; final long[] max = new long[ numDimensions ]; for ( int d = 0; d < numDimensions; ++d ) { min[ d ] = offset[ d ]; max[ d ] = offset[ d ] + block.dimension( d ) - 1; } final RandomAccess< FloatType > randomAccess = source.randomAccess( new FinalInterval( min, max ) ); cursor.jumpFwd( start ); final long[] tmp = new long[ numDimensions ]; for ( long l = 0; l < loopSize; ++l ) { cursor.fwd(); cursor.localize( tmp ); for ( int d = 0; d < numDimensions; ++d ) tmp[ d ] += offset[ d ]; randomAccess.setPosition( tmp ); cursor.get().set( randomAccess.get() ); } }
@Test public void testIntervalPermuteInverseCoordinates() { Img<DoubleType> img = ArrayImgs.doubles(2, 2); Cursor<DoubleType> c = img.cursor(); MersenneTwisterFast r = new MersenneTwisterFast(SEED); while (c.hasNext()) { c.next().set(r.nextDouble()); } IntervalView<DoubleType> expected = Views.permuteCoordinatesInverse(img, new int[]{0, 1}); Cursor<DoubleType> e = expected.cursor(); RandomAccessibleInterval<DoubleType> actual = ops.transform().permuteCoordinatesInverseView(img, new int[]{0, 1}); RandomAccess<DoubleType> actualRA = actual.randomAccess(); while (e.hasNext()) { e.next(); actualRA.setPosition(e); assertEquals(e.get().get(), actualRA.get().get(), 1e-10); } assertTrue(Intervals.equals(expected, actual)); }