/** * TODO * * @param img The {@link Img} to transform. * @param matrix The values of the transformation matrix, ordered as explained above. * @param mode Either LINEAR or NEAREST_NEIGHBOR. */ public Affine3D(final Img<T> img, final float[] matrix, final Mode mode) throws Exception { this(img, matrix, mode, new OutOfBoundsConstantValueFactory<T,Img<T>>(img.firstElement().createVariable())); // default value is zero }
@SuppressWarnings({ "rawtypes", "unchecked" }) private static final NumericType<?> withValue(final Img<? extends NumericType<?>> img, final NumericType<?> type, final Number val) { final NumericType t = img.firstElement().createVariable(); if (ARGBType.class.isAssignableFrom(t.getClass())) { int i = val.intValue(); t.set(new ARGBType(i)); } else { ((RealType)t).setReal(val.doubleValue()); } return t; }
/** * Computes a Gaussian convolution with any precision on an entire {@link Img} using the {@link OutOfBoundsMirrorFactory} with single boundary * * @param sigma - the sigma for the convolution * @param input - the input {@link Img} */ public GaussNativeType( final double[] sigma, final Img<T> input, final OutOfBoundsFactory< T, Img<T> > outOfBounds ) { this( sigma, Views.extend( input, outOfBounds ), input, input.factory(), input.firstElement().createVariable() ); }
@Override public Labeling< LL > create( final long[] dim ) { return new NativeImgLabeling< LL, I >( img.factory().create( dim, img.firstElement().createVariable() ) ); } };
private void assertIncreasing( List< Img< IntType > > images ) { for ( int i = 0; i < images.size(); i++ ) { Img< IntType > image = images.get( i ); assertEquals( i, image.firstElement().get() ); } }
protected < T extends BooleanType< T > > Img< T > calculate( final Img< T > source ) { final Img< T > target = source.factory().create( source ); final T extendedVal = source.firstElement().createVariable(); extendedVal.set( getExtendedValue() ); final ExtendedRandomAccessibleInterval< T, Img< T > > extended = Views.extendValue( source, extendedVal ); calculate( extended, target ); return target; }
@BeforeClass public static void createImg() { Img<UnsignedByteType> tmp = ArrayImgs.unsignedBytes(new long[] { 100, 100 }); Random rand = new Random(1234567890L); final Cursor<UnsignedByteType> cursor = tmp.cursor(); while (cursor.hasNext()) { cursor.next().set(rand.nextInt((int) tmp.firstElement().getMaxValue())); } img = tmp; }
/** * @see LocalMaxEntropyThreshold */ @Test public void testLocalMaxEntropyThreshold() { ops.run(MaxEntropy.class, out, in, new RectangleShape(1, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE)); assertEquals(false, out.firstElement().get()); }
/** * @see LocalMedianThreshold */ @Test public void testLocalMedianThreshold() { ops.run(LocalMedianThreshold.class, out, in, new RectangleShape(3, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE), 0.0); assertEquals(true, out.firstElement().get()); }
/** * @see LocalMinErrorThreshold */ @Test public void testLocalMinErrorThreshold() { ops.run(MinError.class, out, in, new RectangleShape(1, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE)); assertEquals(true, out.firstElement().get()); }
/** * @see LocalNiblackThreshold */ @Test public void testLocalNiblackThreshold() { ops.run(LocalNiblackThreshold.class, out, in, new RectangleShape(1, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE), 0.2, 0.0); assertEquals(true, out.firstElement().get()); }
/** * @see LocalRenyiEntropyThreshold */ @Test public void testLocalRenyiEntropyThreshold() { ops.run(RenyiEntropy.class, out, in, new RectangleShape(1, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE)); assertEquals(false, out.firstElement().get()); }
/** * @see LocalShanbhagThreshold */ @Test public void testLocalShanbhagThreshold() { ops.run(Shanbhag.class, out, in, new RectangleShape(1, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE)); assertEquals(false, out.firstElement().get()); }
/** * @see LocalYenThreshold */ @Test public void testLocalYenThreshold() { ops.run(Yen.class, out, in, new RectangleShape(1, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE)); assertEquals(false, out.firstElement().get()); }
@Test public void copyTypeTest() { Img<FloatType> inputFloat = new ArrayImgFactory<FloatType>().create( new int[] { 120, 100 }, new FloatType()); @SuppressWarnings("unchecked") Img<FloatType> output = (Img<FloatType>) ops .run(CopyII.class, inputFloat); assertTrue("Should be FloatType.", output.firstElement() instanceof FloatType); }
/** * @see LocalHuangThreshold */ @Test public void testLocalHuangThreshold() { ops.run(Huang.class, out, in, new RectangleShape(1, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE)); assertEquals(true, out.firstElement().get()); }
/** * @see LocalPercentileThreshold */ @Test public void testLocalPercentileThreshold() { ops.run(Percentile.class, out, in, new RectangleShape(1, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE)); assertEquals(false, out.firstElement().get()); }
/** * @see LocalRosinThreshold */ @Test public void testLocalRosinThreshold() { ops.run(Rosin.class, out, in, new RectangleShape(1, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE)); assertEquals(false, out.firstElement().get()); }
@Test public void copyArrayImgWithOutputTest() { final Img<UnsignedByteType> output = input.factory().create(input, input.firstElement()); ops.run(CopyArrayImg.class, output, input); final Cursor<UnsignedByteType> inc = input.cursor(); final Cursor<UnsignedByteType> outc = output.cursor(); while (inc.hasNext()) { assertTrue(outc.next().equals(inc.next())); } } }
@Test public void copyRAIWithOutputTest() { final Img<UnsignedByteType> output = input.factory().create(input, input .firstElement()); ops.run(CopyRAI.class, output, input); final Cursor<UnsignedByteType> inc = input.cursor(); final Cursor<UnsignedByteType> outc = output.cursor(); while (inc.hasNext()) { assertEquals(inc.next().get(), outc.next().get()); } }