Refine search
private int countForeground(final IterableInterval<BitType> interval) { int count = 0; for (final BitType element : interval) { count = count + element.getInteger(); } return count; }
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()); } } }
@Override public boolean contains( final double[] position ) { /* * Quantize by nearest-neighbor (-0.5 < x < 0.5) */ validate(); for ( int i = 0; i < numDimensions(); i++ ) { final long lPosition = ( long ) ( position[ i ] - origin[ i ] ); if ( ( lPosition < minima[ i ] ) || ( lPosition > maxima[ i ] ) ) return false; randomAccess.get().setPosition( lPosition, i ); } return randomAccess.get().get().get(); }
private void drawLine( final RandomAccess< BitType > ra, final Polygon poly, final int idx1, final int idx2, final int dimX, final int dimY ) { p1[ 0 ] = poly.xpoints[ idx1 ]; p1[ 1 ] = poly.ypoints[ idx1 ]; p2[ 0 ] = poly.xpoints[ idx2 ]; p2[ 1 ] = poly.ypoints[ idx2 ]; final int[][] points = rasterizeLine( p1, p2 ); for ( final int[] p : points ) { ra.setPosition( p[ 0 ], dimX ); ra.setPosition( p[ 1 ], dimY ); ra.get().set( true ); } }
public static Img<BitType> drawCube(final long width, final long height, final long depth, final long padding) { final long totalPadding = 2 * padding; final Img<BitType> cube = ArrayImgs.bits(width + totalPadding, height + totalPadding, depth + totalPadding); final long x1 = padding + width; final long y1 = padding + height; final long z1 = padding + depth; final RandomAccess<BitType> access = cube.randomAccess(); for (long z = padding; z < z1; z++) { access.setPosition(z, 2); for (long y = padding; y < y1; y++) { access.setPosition(y, 1); for (long x = padding; x < x1; x++) { access.setPosition(x, 0); access.get().setOne(); } } } return cube; } }
/** * Test with a cube that has a cavity inside * <p> * Here χ = β_0 - β_1 + β_2 = 1 - 0 + 1 = 2 * </p> */ @Test public void testHollowCube() throws Exception { final Img<BitType> img = drawCube(3, 3, 3, 1); final RandomAccess<BitType> access = img.randomAccess(); // Add a cavity access.setPosition(new long[]{2, 2, 2}); access.get().setZero(); final double result = ops.topology().eulerCharacteristic26N(img).get(); assertEquals("Euler characteristic (χ) is incorrect", 2.0, result, 1e-12); }
result = img.factory().imgFactory(new BitType()).create( dim, new BitType() ); } catch (IncompatibleTypeException e) { throw new RuntimeException(e); cursorInput.setPosition( cursor ); cursorOutput.setPosition( cursor ); final float in = cursorInput.get().getRealFloat(); if ( in < ditheringThreshold ) cursorOutput.get().setZero(); error = in - minValue; cursorOutput.get().setOne(); error = in - maxValue;
RandomAccess<BitType> raMask = mask.randomAccess(); for (BitType b : mask) { b.setZero(); raMask.setPosition(new int[] { x, y }); raMask.get().setOne();
for ( x0 = -2; x0 < 0; x0++ ) op.setPosition( x0, 0 ); roiCur.reset(); while ( roiCur.hasNext() ) for ( i = 1; i < dim.length; i++ ) op.setPosition( lineCur.getLongPosition( i ) + roiCur.getLongPosition( i ) - 1, i ); kernel[ kernelIndex ] = op.get().getInteger(); sum += kernel[ kernelIndex ]; kernelIndex = ( kernelIndex + 1 ) % kernel.length; kernel[ kernelIndex ] = op.get().getInteger(); sum += kernel[ kernelIndex ]; kernelIndex = ( kernelIndex + 1 ) % kernel.length; r.get().set( ( kernelSize - sum ) < count ); r.get().set( sum >= count );
@Override public String toString() { final boolean value = get(); return value ? "1" : "0"; }
@Override public BitType createOutput() { return new BitType(); } }
/** * Tests {@link BitType#setBigInteger(BigInteger)} and ensures that the value * returned is within BitType range. */ @Test public void testSetBigInteger() { final BitType ul = new BitType( false ); assertEquals( ul.get(), false ); final BigInteger bi = new BigInteger( "AAAAAA3141343BBBBBBBBBBB4134", 16 ); ul.setBigInteger( bi ); assertEquals( ul.get(), true ); }
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); }