public AbstractNeighborhoodCursor(AbstractNeighborhood<T> neighborhood) { this.neighborhood = neighborhood; this.ra = neighborhood.extendedSource.randomAccess(); }
public SquareNeighborhoodCursor3x3(ExtendedRandomAccessibleInterval<T,RandomAccessibleInterval<T>> extendedSource, long[] center) { this.source = extendedSource; this.center = center; this.ra = extendedSource.randomAccess(); reset(); }
@SuppressWarnings({"rawtypes","unchecked"}) public ComplexImageFunction( Img<I> img, OutOfBoundsFactory<I,Img<I>> factory, O type) { this(new ExtendedRandomAccessibleInterval(img, factory).randomAccess(), type); }
/** * Constructs a new 2x2x2 neighborhood * * <p> * <em>NB</em>: Copies reference * </p> * * @param interval Image space where the neighborhood is located */ public Octant(final RandomAccessibleInterval<B> interval) { access = Views.extendZero(interval).randomAccess(); }
public SquareNeighborhoodCursor3x3(ExtendedRandomAccessibleInterval<T,RandomAccessibleInterval<T>> extendedSource, long[] center) { this.source = extendedSource; this.center = center; this.ra = extendedSource.randomAccess(); reset(); }
@Override final public RandomAccess< T > randomAccess( final Interval interval ) { assert source.numDimensions() == interval.numDimensions(); if ( Intervals.contains( source, interval ) ) { return source.randomAccess( interval ); } return randomAccess(); }
@Override final public RandomAccess< T > randomAccess( final Interval interval ) { assert source.numDimensions() == interval.numDimensions(); if ( Intervals.contains( source, interval ) ) { return source.randomAccess( interval ); } return randomAccess(); }
public Traverser(RandomAccessibleInterval<B> interval) { xSize = interval.dimension(0); ySize = interval.dimension(1); zSize = interval.dimension(2); x1 = xSize - 1; y1 = ySize - 1; z1 = zSize - 1; access = Views.extendZero(interval).randomAccess(); } }
/** * Checks if an element is part of the outline of an object * * @param source the location of the element * @param coordinates coordinates of the element * @return true if element is foreground and has at least one background * neighbour */ private boolean isOutline( final ExtendedRandomAccessibleInterval<B, RandomAccessibleInterval<B>> source, final long[] coordinates) { final OutOfBounds<B> access = source.randomAccess(); access.setPosition(coordinates); if (!access.get().get()) { return false; } final IntervalView<B> neighbourhood = neighbourhoodInterval(source, coordinates); return isAnyBackground(neighbourhood); } // endregion
@Override public RandomAccessibleInterval< T > compute( final RandomAccessibleInterval< T > input, final RandomAccessibleInterval< T > output ) { final StructuringElementCursor< T > inStructure = new StructuringElementCursor< T >( Views.extend( input, m_factory ).randomAccess(), m_struc ); final Cursor< T > out = Views.iterable( output ).localizingCursor(); double m; while ( out.hasNext() ) { out.next(); inStructure.relocate( out ); inStructure.next(); m = inStructure.get().getRealDouble(); while ( inStructure.hasNext() ) { inStructure.next(); m = Math.min( m, inStructure.get().getRealDouble() ); } out.get().setReal( m ); } return output; }
@Override public RandomAccessibleInterval< T > compute( final RandomAccessibleInterval< T > input, final RandomAccessibleInterval< T > output ) { final StructuringElementCursor< T > inStructure = new StructuringElementCursor< T >( Views.extend( input, m_factory ).randomAccess(), m_struc ); final Cursor< T > out = Views.iterable( output ).localizingCursor(); double m; while ( out.hasNext() ) { out.next(); inStructure.relocate( out ); inStructure.next(); m = inStructure.get().getRealDouble(); while ( inStructure.hasNext() ) { inStructure.next(); m = Math.max( m, inStructure.get().getRealDouble() ); } out.get().setReal( m ); } return output; }
private Labeling< L > computeLabelBased( final Labeling< L > input, final Labeling< L > output ) { final StructuringElementCursor< LabelingType< L >> outStructure = new StructuringElementCursor< LabelingType< L >>( Views.extendValue( output, new LabelingType< L >() ).randomAccess(), m_struc ); for ( final L label : input.getLabels() ) { final Cursor< LabelingType< L >> in = input.getIterableRegionOfInterest( label ).getIterableIntervalOverROI( input ).localizingCursor(); while ( in.hasNext() ) { in.next(); outStructure.relocate( in ); while ( outStructure.hasNext() ) { outStructure.next(); addLabel( outStructure.get(), label ); } } } return output; }
@Test public void extendMirrorDoubleTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType()); OutOfBounds<DoubleType> il2 = Views.extendMirrorDouble(img).randomAccess(); OutOfBounds<DoubleType> opr = ops.transform().extendMirrorDoubleView(img).randomAccess(); il2.setPosition(new int[] { -1, -1 }); opr.setPosition(new int[] { -1, -1 }); assertEquals(il2.get().get(), opr.get().get(), 1e-10); il2.setPosition(new int[] { 11, 11 }); opr.setPosition(new int[] { 11, 11 }); assertEquals(il2.get().get(), opr.get().get(), 1e-10); }
@Test public void extendZeroTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType()); OutOfBounds<DoubleType> il2 = Views.extendZero(img).randomAccess(); OutOfBounds<DoubleType> opr = ops.transform().extendZeroView(img).randomAccess(); il2.setPosition(new int[] { -1, -1 }); opr.setPosition(new int[] { -1, -1 }); assertEquals(il2.get().get(), opr.get().get(), 1e-10); il2.setPosition(new int[] { 11, 11 }); opr.setPosition(new int[] { 11, 11 }); assertEquals(il2.get().get(), opr.get().get(), 1e-10); }
@Test public void extendPeriodicTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType()); OutOfBounds<DoubleType> il2 = Views.extendPeriodic(img).randomAccess(); OutOfBounds<DoubleType> opr = ops.transform().extendPeriodicView(img).randomAccess(); il2.setPosition(new int[] { -1, -1 }); opr.setPosition(new int[] { -1, -1 }); assertEquals(il2.get().get(), opr.get().get(), 1e-10); il2.setPosition(new int[] { 11, 11 }); opr.setPosition(new int[] { 11, 11 }); assertEquals(il2.get().get(), opr.get().get(), 1e-10); }
@Test public void extendRandomTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType()); OutOfBounds<DoubleType> il2 = Views.extendRandom(img, 0, 0).randomAccess(); OutOfBounds<DoubleType> opr = ops.transform().extendRandomView(img, 0, 0).randomAccess(); il2.setPosition(new int[] { -1, -1 }); opr.setPosition(new int[] { -1, -1 }); assertEquals(il2.get().get(), opr.get().get(), 1e-10); il2.setPosition(new int[] { 11, 11 }); opr.setPosition(new int[] { 11, 11 }); assertEquals(il2.get().get(), opr.get().get(), 1e-10); }
@Test public void extendBorderTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType()); OutOfBounds<DoubleType> il2 = Views.extendBorder(img).randomAccess(); OutOfBounds<DoubleType> opr = ops.transform().extendBorderView(img).randomAccess(); il2.setPosition(new int[] { -1, -1 }); opr.setPosition(new int[] { -1, -1 }); assertEquals(il2.get().get(), opr.get().get(), 1e-10); il2.setPosition(new int[] { 11, 11 }); opr.setPosition(new int[] { 11, 11 }); assertEquals(il2.get().get(), opr.get().get(), 1e-10); }
@Test public void extendMirrorSingleTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType()); OutOfBounds<DoubleType> il2 = Views.extendMirrorSingle(img).randomAccess(); OutOfBounds<DoubleType> opr = ops.transform().extendMirrorSingleView(img).randomAccess(); il2.setPosition(new int[] { -1, -1 }); opr.setPosition(new int[] { -1, -1 }); assertEquals(il2.get().get(), opr.get().get(), 1e-10); il2.setPosition(new int[] { 11, 11 }); opr.setPosition(new int[] { 11, 11 }); assertEquals(il2.get().get(), opr.get().get(), 1e-10); }
@Test public void extendValueTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType()); OutOfBounds<DoubleType> il2 = Views.extendValue(img, new DoubleType(0)).randomAccess(); OutOfBounds<DoubleType> opr = ops.transform().extendValueView(img, new DoubleType(0)).randomAccess(); il2.setPosition(new int[] { -1, -1 }); opr.setPosition(new int[] { -1, -1 }); assertEquals(il2.get().get(), opr.get().get(), 1e-10); il2.setPosition(new int[] { 11, 11 }); opr.setPosition(new int[] { 11, 11 }); assertEquals(il2.get().get(), opr.get().get(), 1e-10); }
@Test public void defaultExtendTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType()); OutOfBounds<DoubleType> il2 = Views .extend(img, new OutOfBoundsBorderFactory<DoubleType, RandomAccessibleInterval<DoubleType>>()) .randomAccess(); OutOfBounds<DoubleType> opr = ops.transform() .extendView(img, new OutOfBoundsBorderFactory<DoubleType, RandomAccessibleInterval<DoubleType>>()) .randomAccess(); il2.setPosition(new int[] { -1, -1 }); opr.setPosition(new int[] { -1, -1 }); assertEquals(il2.get().get(), opr.get().get(), 1e-10); il2.setPosition(new int[] { 11, 11 }); opr.setPosition(new int[] { 11, 11 }); assertEquals(il2.get().get(), opr.get().get(), 1e-10); }