@Override public IntervalView<T> calculate(RandomAccessibleInterval<T> input) { return Views.permuteCoordinatesInverse(input, permutation); }
/** * Inverse bijective permutation of the integer coordinates of one dimension * of a {@link RandomAccessibleInterval}. * * @param source * must have dimension(dimension) == permutation.length * @param permutation * must be a bijective permutation over its index set, i.e. for a * lut of length n, the sorted content the array must be * [0,...,n-1] which is the index set of the lut. * @param d * dimension index to be permuted * * @return {@link IntervalView} of permuted source. * * @deprecated use {@link Views#permuteCoordinatesInverse(RandomAccessibleInterval, int[], int)} */ @Deprecated public static < T > IntervalView< T > permuteCoordinateInverse( final RandomAccessibleInterval< T > source, final int[] permutation, final int d ) { return permuteCoordinatesInverse(source, permutation, d); }
/** * Inverse bijective permutation of the integer coordinates of one dimension * of a {@link RandomAccessibleInterval}. * * @param source * must have dimension(dimension) == permutation.length * @param permutation * must be a bijective permutation over its index set, i.e. for a * lut of length n, the sorted content the array must be * [0,...,n-1] which is the index set of the lut. * @param d * dimension index to be permuted * * @return {@link IntervalView} of permuted source. * * @deprecated use {@link Views#permuteCoordinatesInverse(RandomAccessibleInterval, int[], int)} */ @Deprecated public static < T > IntervalView< T > permuteCoordinateInverse( final RandomAccessibleInterval< T > source, final int[] permutation, final int d ) { return permuteCoordinatesInverse(source, permutation, d); }
@Test public void permuteCoordinatesInverseOfDimensionTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{2, 2}, new DoubleType()); Cursor<DoubleType> c = img.cursor(); MersenneTwisterFast r = new MersenneTwisterFast(SEED); while (c.hasNext()) { c.next().set(r.nextDouble()); } IntervalView<DoubleType> out = Views.permuteCoordinatesInverse(img, new int[]{0, 1}, 1); Cursor<DoubleType> il2 = out.cursor(); RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesInverseView(img, new int[]{0, 1}, 1).randomAccess(); while (il2.hasNext()) { il2.next(); opr.setPosition(il2); assertEquals(il2.get().get(), opr.get().get(), 1e-10); } }
@Test public void defaultPermuteCoordinatesInverseTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{2, 2}, new DoubleType()); Cursor<DoubleType> c = img.cursor(); MersenneTwisterFast r = new MersenneTwisterFast(SEED); while (c.hasNext()) { c.next().set(r.nextDouble()); } Cursor<DoubleType> il2 = Views.permuteCoordinatesInverse(img, new int[]{0, 1}).cursor(); RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesInverseView(img, new int[]{0, 1}).randomAccess(); while (il2.hasNext()) { il2.next(); opr.setPosition(il2); assertEquals(il2.get().get(), opr.get().get(), 1e-10); } }
@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)); }
@Test public void testIntervalPermuteInverseDimensionCoordinates() { 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}, 1); Cursor<DoubleType> e = expected.cursor(); RandomAccessibleInterval<DoubleType> actual = ops.transform().permuteCoordinatesInverseView(img, new int[]{0, 1}, 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)); } }
final TransformView< LongType > bijectivePermutation = new TransformView< LongType >( img, t ); final TransformView< LongType > inverseBijectivePermutation = new TransformView< LongType >( bijectivePermutation, t.inverse() ); final IntervalView< LongType > viewTransformed = Views.permuteCoordinatesInverse( img, PermutationTransformTest.lut ); final IntervalView< LongType > identity = Views.permuteCoordinates( viewTransformed, PermutationTransformTest.lut );
final TransformView< IntType > inversed = new TransformView< IntType >( transformed, inverse ); final IntervalView< IntType > viewTransformed = Views.permuteCoordinatesInverse( this.img, this.lut, this.d ); final IntervalView< IntType > identity = Views.permuteCoordinates( viewTransformed, this.lut, this.d );