@Override public IntervalView<T> calculate(final RandomAccessibleInterval<T> input) { return Views.permute(input, fromAxis, toAxis); }
@Override public MixedTransformView<T> calculate(RandomAccessible<T> input) { return Views.permute(input, fromAxis, toAxis); }
/** * Create view with permuted axes. fromAxis is moved to toAxis. While the * order of the other axes is preserved. * * If fromAxis=2 and toAxis=4, and axis order of image is XYCZT, then * a view to the image with axis order XYZTC would be created. */ public static < T > RandomAccessible< T > moveAxis( final RandomAccessible< T > image, final int fromAxis, final int toAxis ) { if ( fromAxis == toAxis ) return image; final int direction = toAxis > fromAxis ? 1 : -1; RandomAccessible< T > res = image; for ( int i = fromAxis; i != toAxis; i += direction ) res = Views.permute( res, i, i + direction ); return res; }
/** * Create view with permuted axes. fromAxis is moved to toAxis. While the * order of the other axes is preserved. * * If fromAxis=2 and toAxis=4, and axis order of image is XYCZT, then * a view to the image with axis order XYZTC would be created. */ public static < T > RandomAccessibleInterval< T > moveAxis( final RandomAccessibleInterval< T > image, final int fromAxis, final int toAxis ) { if ( fromAxis == toAxis ) return image; final int direction = toAxis > fromAxis ? 1 : -1; RandomAccessibleInterval< T > res = image; for ( int i = fromAxis; i != toAxis; i += direction ) res = Views.permute( res, i, i + direction ); return res; }
/** * Create view with permuted axes. fromAxis is moved to toAxis. While the * order of the other axes is preserved. * * If fromAxis=2 and toAxis=4, and axis order of image is XYCZT, then * a view to the image with axis order XYZTC would be created. */ public static < T > RandomAccessible< T > moveAxis( final RandomAccessible< T > image, final int fromAxis, final int toAxis ) { if ( fromAxis == toAxis ) return image; final int direction = toAxis > fromAxis ? 1 : -1; RandomAccessible< T > res = image; for ( int i = fromAxis; i != toAxis; i += direction ) res = Views.permute( res, i, i + direction ); return res; }
/** * Create view with permuted axes. fromAxis is moved to toAxis. While the * order of the other axes is preserved. * * If fromAxis=2 and toAxis=4, and axis order of image is XYCZT, then * a view to the image with axis order XYZTC would be created. */ public static < T > RandomAccessibleInterval< T > moveAxis( final RandomAccessibleInterval< T > image, final int fromAxis, final int toAxis ) { if ( fromAxis == toAxis ) return image; final int direction = toAxis > fromAxis ? 1 : -1; RandomAccessibleInterval< T > res = image; for ( int i = fromAxis; i != toAxis; i += direction ) res = Views.permute( res, i, i + direction ); return res; }
sourceStacks.set( i, Views.permute( sourceStacks.get( i ), 2, 3 ) );
/** * Create view with permuted axes. fromAxis and toAxis are swapped. * * If fromAxis=0 and toAxis=2, this means that the X-axis of the source view * is mapped to the Z-Axis of the permuted view and vice versa. For a XYZ * source, a ZYX view would be created. */ public static < T > IntervalView< T > permute( final RandomAccessibleInterval< T > interval, final int fromAxis, final int toAxis ) { final int n = interval.numDimensions(); final long[] min = new long[ n ]; final long[] max = new long[ n ]; interval.min( min ); interval.max( max ); final long fromMinNew = min[ toAxis ]; final long fromMaxNew = max[ toAxis ]; min[ toAxis ] = min[ fromAxis ]; max[ toAxis ] = max[ fromAxis ]; min[ fromAxis ] = fromMinNew; max[ fromAxis ] = fromMaxNew; return Views.interval( Views.permute( ( RandomAccessible< T > ) interval, fromAxis, toAxis ), min, max ); }
/** * Create view with permuted axes. fromAxis and toAxis are swapped. * * If fromAxis=0 and toAxis=2, this means that the X-axis of the source view * is mapped to the Z-Axis of the permuted view and vice versa. For a XYZ * source, a ZYX view would be created. */ public static < T > IntervalView< T > permute( final RandomAccessibleInterval< T > interval, final int fromAxis, final int toAxis ) { final int n = interval.numDimensions(); final long[] min = new long[ n ]; final long[] max = new long[ n ]; interval.min( min ); interval.max( max ); final long fromMinNew = min[ toAxis ]; final long fromMaxNew = max[ toAxis ]; min[ toAxis ] = min[ fromAxis ]; max[ toAxis ] = max[ fromAxis ]; min[ fromAxis ] = fromMinNew; max[ fromAxis ] = fromMaxNew; return Views.interval( Views.permute( ( RandomAccessible< T > ) interval, fromAxis, toAxis ), min, max ); }
interval = new FinalInterval( min, max ); for ( int i = 0; i < sourceStacks.size(); ++i ) sourceStacks.set( i, Views.permute( sourceStacks.get( i ), 2, 3 ) );
private static < T extends RealType< T >, U extends RealType< U > > void transformL1AlongDimension( final RandomAccessible< T > source, final RandomAccessibleInterval< U > target, final int dim, final double weight ) { final int lastDim = target.numDimensions() - 1; final long size = target.dimension( dim ); final RealComposite< DoubleType > tmp = Views.collapseReal( createAppropriateOneDimensionalImage( size, new DoubleType() ) ).randomAccess().get(); // do not permute if we already work on last dimension final Cursor< RealComposite< T > > s = Views.flatIterable( Views.collapseReal( dim == lastDim ? Views.interval( source, target ) : Views.permute( Views.interval( source, target ), dim, lastDim ) ) ).cursor(); final Cursor< RealComposite< U > > t = Views.flatIterable( Views.collapseReal( dim == lastDim ? target : Views.permute( target, dim, lastDim ) ) ).cursor(); while ( s.hasNext() ) { final RealComposite< T > sourceComp = s.next(); final RealComposite< U > targetComp = t.next(); for ( long i = 0; i < size; ++i ) { tmp.get( i ).set( sourceComp.get( i ).getRealDouble() ); } transformL1SingleColumn( tmp, targetComp, weight, size ); } }
private static < T extends RealType< T >, U extends RealType< U > > void transformAlongDimension( final RandomAccessible< T > source, final RandomAccessibleInterval< U > target, final Distance d, final int dim ) { final int lastDim = target.numDimensions() - 1; final long size = target.dimension( dim ); final RealComposite< DoubleType > tmp = Views.collapseReal( createAppropriateOneDimensionalImage( size, new DoubleType() ) ).randomAccess().get(); // do not permute if we already work on last dimension final Cursor< RealComposite< T > > s = Views.flatIterable( Views.collapseReal( dim == lastDim ? Views.interval( source, target ) : Views.permute( Views.interval( source, target ), dim, lastDim ) ) ).cursor(); final Cursor< RealComposite< U > > t = Views.flatIterable( Views.collapseReal( dim == lastDim ? target : Views.permute( target, dim, lastDim ) ) ).cursor(); final RealComposite< LongType > lowerBoundDistanceIndex = Views.collapseReal( createAppropriateOneDimensionalImage( size, new LongType() ) ).randomAccess().get(); final RealComposite< DoubleType > envelopeIntersectLocation = Views.collapseReal( createAppropriateOneDimensionalImage( size + 1, new DoubleType() ) ).randomAccess().get(); while ( s.hasNext() ) { final RealComposite< T > sourceComp = s.next(); final RealComposite< U > targetComp = t.next(); for ( long i = 0; i < size; ++i ) { tmp.get( i ).set( sourceComp.get( i ).getRealDouble() ); } transformSingleColumn( tmp, targetComp, lowerBoundDistanceIndex, envelopeIntersectLocation, d, dim, size ); } }
@Test public void defaultPermuteTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{10, 10}, new DoubleType()); MixedTransformView<DoubleType> il2 = Views.permute((RandomAccessible<DoubleType>)img, 1, 0); MixedTransformView<DoubleType> opr = ops.transform().permuteView(deinterval(img), 1, 0); for (int i = 0; i < il2.getTransformToSource().getMatrix().length; i++) { for (int j = 0; j < il2.getTransformToSource().getMatrix()[i].length; j++) { assertEquals(il2.getTransformToSource().getMatrix()[i][j], opr.getTransformToSource().getMatrix()[i][j], 1e-10); } } }
@Test public void testIntervalPermute() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{10, 10}, new DoubleType()); IntervalView<DoubleType> expected = Views.permute((RandomAccessibleInterval<DoubleType>)img, 1, 0); IntervalView<DoubleType> actual = ops.transform().permuteView((RandomAccessibleInterval<DoubleType>)img, 1, 0); for (int i = 0; i < ((MixedTransformView<DoubleType>) expected.getSource()).getTransformToSource().getMatrix().length; i++) { for (int j = 0; j < ((MixedTransformView<DoubleType>) expected.getSource()).getTransformToSource().getMatrix()[i].length; j++) { assertEquals(((MixedTransformView<DoubleType>) expected.getSource()).getTransformToSource().getMatrix()[i][j], ((MixedTransformView<DoubleType>) actual.getSource()).getTransformToSource().getMatrix()[i][j], 1e-10); } } }
resRndAccessible = Views.permute(resRndAccessible, srcIdx, d);
resRndAccessible = Views.permute(resRndAccessible, srcIdx, d);