/** * Negative shear transform of a RandomAccessible using * {@link InverseShearTransform}, i.e. c[ shearDimension ] = c[ * shearDimension ] - c[ referenceDimension ] * * @param source * input, e.g. extended {@link RandomAccessibleInterval} * @param shearDimension * dimension to be sheared * @param referenceDimension * reference dimension for shear * * @return {@link TransformView} containing the result. */ public static < T > TransformView< T > unshear( final RandomAccessible< T > source, final int shearDimension, final int referenceDimension ) { final InverseShearTransform transform = new InverseShearTransform( source.numDimensions(), shearDimension, referenceDimension ); return new TransformView<>( source, transform.inverse() ); }
/** * Negative shear transform of a RandomAccessible using * {@link InverseShearTransform}, i.e. c[ shearDimension ] = c[ * shearDimension ] - c[ referenceDimension ] * * @param source * input, e.g. extended {@link RandomAccessibleInterval} * @param shearDimension * dimension to be sheared * @param referenceDimension * reference dimension for shear * * @return {@link TransformView} containing the result. */ public static < T > TransformView< T > unshear( final RandomAccessible< T > source, final int shearDimension, final int referenceDimension ) { final InverseShearTransform transform = new InverseShearTransform( source.numDimensions(), shearDimension, referenceDimension ); return new TransformView<>( source, transform.inverse() ); }
/** * Positive shear transform of a RandomAccessible using * {@link ShearTransform}, i.e. c[ shearDimension ] = c[ shearDimension ] + * c[ referenceDimension ] * * @param source * input, e.g. extended {@link RandomAccessibleInterval} * @param shearDimension * dimension to be sheared * @param referenceDimension * reference dimension for shear * * @return {@link TransformView} containing the result. */ public static < T > TransformView< T > shear( final RandomAccessible< T > source, final int shearDimension, final int referenceDimension ) { final ShearTransform transform = new ShearTransform( source.numDimensions(), shearDimension, referenceDimension ); return new TransformView<>( source, transform.inverse() ); }
/** * Positive shear transform of a RandomAccessible using * {@link ShearTransform}, i.e. c[ shearDimension ] = c[ shearDimension ] + * c[ referenceDimension ] * * @param source * input, e.g. extended {@link RandomAccessibleInterval} * @param shearDimension * dimension to be sheared * @param referenceDimension * reference dimension for shear * * @return {@link TransformView} containing the result. */ public static < T > TransformView< T > shear( final RandomAccessible< T > source, final int shearDimension, final int referenceDimension ) { final ShearTransform transform = new ShearTransform( source.numDimensions(), shearDimension, referenceDimension ); return new TransformView<>( source, transform.inverse() ); }
/** * Bijective permutation of the integer coordinates in each dimension of a * {@link RandomAccessibleInterval}. * * @param source * must be an <em>n</em>-dimensional hypercube with each * dimension being of the same size as the permutation array * @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. * * @return {@link IntervalView} of permuted source. */ public static < T > IntervalView< T > permuteCoordinates( final RandomAccessibleInterval< T > source, final int[] permutation ) { assert AbstractPermutationTransform.checkBijectivity( permutation ): "Non-bijective LUT passed for coordinate permuation."; assert PermutationTransform.checkInterval( source, permutation ): "Source interval boundaries do not match permutation."; final int nDim = source.numDimensions(); final PermutationTransform transform = new PermutationTransform( permutation, nDim, nDim ); return Views.interval( new TransformView<>( source, transform.inverse() ), source ); }
/** * Bijective permutation of the integer coordinates in each dimension of a * {@link RandomAccessibleInterval}. * * @param source * must be an <em>n</em>-dimensional hypercube with each * dimension being of the same size as the permutation array * @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. * * @return {@link IntervalView} of permuted source. */ public static < T > IntervalView< T > permuteCoordinates( final RandomAccessibleInterval< T > source, final int[] permutation ) { assert AbstractPermutationTransform.checkBijectivity( permutation ): "Non-bijective LUT passed for coordinate permuation."; assert PermutationTransform.checkInterval( source, permutation ): "Source interval boundaries do not match permutation."; final int nDim = source.numDimensions(); final PermutationTransform transform = new PermutationTransform( permutation, nDim, nDim ); return Views.interval( new TransformView<>( source, transform.inverse() ), source ); }
/** * Inverse Bijective permutation of the integer coordinates in each * dimension of a {@link RandomAccessibleInterval}. * * @param source * must be an <em>n</em>-dimensional hypercube with each * dimension being of the same size as the permutation array * @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. * * @return {@link IntervalView} of permuted source. */ public static < T > IntervalView< T > permuteCoordinatesInverse( final RandomAccessibleInterval< T > source, final int[] permutation ) { assert AbstractPermutationTransform.checkBijectivity( permutation ): "Non-bijective LUT passed for coordinate permuation."; assert PermutationTransform.checkInterval( source, permutation ): "Source interval boundaries do not match permutation."; final int nDim = source.numDimensions(); final PermutationTransform transform = new PermutationTransform( permutation, nDim, nDim ).inverse(); return Views.interval( new TransformView<>( source, transform.inverse() ), source ); }
/** * Inverse Bijective permutation of the integer coordinates in each * dimension of a {@link RandomAccessibleInterval}. * * @param source * must be an <em>n</em>-dimensional hypercube with each * dimension being of the same size as the permutation array * @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. * * @return {@link IntervalView} of permuted source. */ public static < T > IntervalView< T > permuteCoordinatesInverse( final RandomAccessibleInterval< T > source, final int[] permutation ) { assert AbstractPermutationTransform.checkBijectivity( permutation ): "Non-bijective LUT passed for coordinate permuation."; assert PermutationTransform.checkInterval( source, permutation ): "Source interval boundaries do not match permutation."; final int nDim = source.numDimensions(); final PermutationTransform transform = new PermutationTransform( permutation, nDim, nDim ).inverse(); return Views.interval( new TransformView<>( source, transform.inverse() ), source ); }
/** * 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. */ public static < T > IntervalView< T > permuteCoordinates( final RandomAccessibleInterval< T > source, final int[] permutation, final int d ) { assert AbstractPermutationTransform.checkBijectivity( permutation ): "Non-bijective LUT passed for coordinate permuation."; assert source.min( d ) == 0: "Source with min[d] coordinate != 0 passed to coordinate permutation."; assert source.dimension( d ) == permutation.length: "Source with dimension[d] != LUT.length passed to coordinate permutation."; final int nDim = source.numDimensions(); final SingleDimensionPermutationTransform transform = new SingleDimensionPermutationTransform( permutation, nDim, nDim, d ); return Views.interval( new TransformView<>( source, transform.inverse() ), source ); }
/** * 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. */ public static < T > IntervalView< T > permuteCoordinates( final RandomAccessibleInterval< T > source, final int[] permutation, final int d ) { assert AbstractPermutationTransform.checkBijectivity( permutation ): "Non-bijective LUT passed for coordinate permuation."; assert source.min( d ) == 0: "Source with min[d] coordinate != 0 passed to coordinate permutation."; assert source.dimension( d ) == permutation.length: "Source with dimension[d] != LUT.length passed to coordinate permutation."; final int nDim = source.numDimensions(); final SingleDimensionPermutationTransform transform = new SingleDimensionPermutationTransform( permutation, nDim, nDim, d ); return Views.interval( new TransformView<>( source, transform.inverse() ), source ); }
/** * 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. */ public static < T > IntervalView< T > permuteCoordinatesInverse( final RandomAccessibleInterval< T > source, final int[] permutation, final int d ) { assert AbstractPermutationTransform.checkBijectivity( permutation ): "Non-bijective LUT passed for coordinate permuation."; assert source.min( d ) == 0: "Source with min[d] coordinate != 0 passed to coordinate permutation."; assert source.dimension( d ) == permutation.length: "Source with dimension[d] != LUT.length passed to coordinate permutation."; final int nDim = source.numDimensions(); final SingleDimensionPermutationTransform transform = new SingleDimensionPermutationTransform( permutation, nDim, nDim, d ).inverse(); return Views.interval( new TransformView<>( source, transform.inverse() ), source ); }
/** * 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. */ public static < T > IntervalView< T > permuteCoordinatesInverse( final RandomAccessibleInterval< T > source, final int[] permutation, final int d ) { assert AbstractPermutationTransform.checkBijectivity( permutation ): "Non-bijective LUT passed for coordinate permuation."; assert source.min( d ) == 0: "Source with min[d] coordinate != 0 passed to coordinate permutation."; assert source.dimension( d ) == permutation.length: "Source with dimension[d] != LUT.length passed to coordinate permutation."; final int nDim = source.numDimensions(); final SingleDimensionPermutationTransform transform = new SingleDimensionPermutationTransform( permutation, nDim, nDim, d ).inverse(); return Views.interval( new TransformView<>( source, transform.inverse() ), source ); }
@Test public void testIdentity() { for ( int source = 0; source < numDimensions; ++source ) { for ( int target = 0; target < numDimensions; ++ target ) { if ( target == source ) continue; ShearTransform tf = new ShearTransform( numDimensions, target, source ); AbstractShearTransform iv = tf.inverse(); TransformView<FloatType> transformed = new TransformView< FloatType >( new TransformView< FloatType >( img, iv ), tf ); ArrayCursor<FloatType> i = img.cursor(); Cursor<FloatType> t = Views.flatIterable( Views.interval( transformed, img ) ).cursor(); while( t.hasNext() ) { Assert.assertTrue( i.hasNext() ); Assert.assertEquals( i.next().get(), t.next().get(), 0.0f ); } Assert.assertFalse( i.hasNext() ); } } }
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 SingleDimensionPermutationTransform inverse = transform.inverse(); final TransformView< IntType > transformed = new TransformView< IntType >( this.img, transform ); final TransformView< IntType > inversed = new TransformView< IntType >( transformed, inverse );
AbstractShearTransform iv = tf.inverse(); ExtendedRandomAccessibleInterval<FloatType, ArrayImg<FloatType, FloatArray>> extended = Views.extendValue( img, new FloatType( Float.NaN ) ); TransformView<FloatType> transformed = new TransformView< FloatType >( extended, iv ); BoundingBox boundingBox = new BoundingBox( img ); tf.transform( boundingBox );
AbstractShearTransform iv = tf.inverse(); ExtendedRandomAccessibleInterval<FloatType, ArrayImg<FloatType, FloatArray>> extended = Views.extendValue( img, new FloatType( Float.NaN ) ); TransformView<FloatType> transformed = new TransformView< FloatType >( extended, tf ); BoundingBox boundingBox = new BoundingBox( img ); iv.transform( boundingBox );