@Override public MixedTransformView<T> calculate(RandomAccessible<T> input) { return Views.rotate(input, fromAxis, toAxis); }
@Override public IntervalView<T> calculate(RandomAccessibleInterval<T> input) { return Views.rotate(input, fromAxis, toAxis); }
static private final <R extends RealType<R>> IntervalView<R> process(final Img<R> img, final Mode mode) { IntervalView<R> iv; if (Mode.R90 == mode) { iv = Views.rotate(img, 0, 1); } else if (Mode.R270 == mode) { iv = Views.rotate(img, 1, 0); } else if (Mode.R180 == mode) { iv = Views.rotate(Views.rotate(img, 0, 1), 0, 1); } else { throw new IllegalArgumentException("Invalid Mode: " + mode); } return Views.zeroMin(iv); } }
/** * Create view that is rotated by 90 degrees. The rotation is specified by * the fromAxis and toAxis arguments. * * If fromAxis=0 and toAxis=1, this means that the X-axis of the source view * is mapped to the Y-Axis of the rotated view. That is, it corresponds to a * 90 degree clock-wise rotation of the source view in the XY plane. * * fromAxis=1 and toAxis=0 corresponds to a counter-clock-wise rotation in * the XY plane. */ public static < T > IntervalView< T > rotate( 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 ); if ( fromAxis != toAxis ) { final long fromMinNew = -max[ toAxis ]; final long fromMaxNew = -min[ toAxis ]; min[ toAxis ] = min[ fromAxis ]; max[ toAxis ] = max[ fromAxis ]; min[ fromAxis ] = fromMinNew; max[ fromAxis ] = fromMaxNew; } return Views.interval( Views.rotate( ( RandomAccessible< T > ) interval, fromAxis, toAxis ), min, max ); }
/** * Create view that is rotated by 90 degrees. The rotation is specified by * the fromAxis and toAxis arguments. * * If fromAxis=0 and toAxis=1, this means that the X-axis of the source view * is mapped to the Y-Axis of the rotated view. That is, it corresponds to a * 90 degree clock-wise rotation of the source view in the XY plane. * * fromAxis=1 and toAxis=0 corresponds to a counter-clock-wise rotation in * the XY plane. */ public static < T > IntervalView< T > rotate( 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 ); if ( fromAxis != toAxis ) { final long fromMinNew = -max[ toAxis ]; final long fromMaxNew = -min[ toAxis ]; min[ toAxis ] = min[ fromAxis ]; max[ toAxis ] = max[ fromAxis ]; min[ fromAxis ] = fromMinNew; max[ fromAxis ] = fromMaxNew; } return Views.interval( Views.rotate( ( RandomAccessible< T > ) interval, fromAxis, toAxis ), min, max ); }
final Img< FloatType > maxAvgPSF = PSFCombination.computeMaxAverageTransformedPSF( psfs.values(), new ArrayImgFactory< FloatType >() ); DisplayImage.getImagePlusInstance( Views.rotate( avgPSF, 0, 2 ), false, "avgPSF", 0, 1 ).show(); DisplayImage.getImagePlusInstance( maxAvgPSF, false, "maxAvgPSF", 0, 1 ).show();
@Test public void testDefaultRotate() { final Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 20, 10 }, new DoubleType()); final MixedTransformView<DoubleType> il2 = Views.rotate((RandomAccessible<DoubleType>) img, 1, 0); final MixedTransformView<DoubleType> opr = ops.transform().rotateView(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 testIntervalRotate() { final Img<DoubleType> img = ArrayImgs.doubles(20,10); final IntervalView<DoubleType> il2 = Views.rotate((RandomAccessibleInterval<DoubleType>) img, 1, 0); final IntervalView<DoubleType> opr = (IntervalView<DoubleType>) ops.transform().rotateView((RandomAccessibleInterval<DoubleType>) img, 1, 0); for (int i = 0; i < ((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource() .getMatrix().length; i++) { for (int j = 0; j < ((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource() .getMatrix()[i].length; j++) { assertEquals( ((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource().getMatrix()[i][j], ((MixedTransformView<DoubleType>) opr.getSource()).getTransformToSource().getMatrix()[i][j], 1e-10); } } }
@Test public void testIntervalRotateInterval() { final Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 20, 10 }, new DoubleType()); final IntervalView<DoubleType> il2 = Views.rotate((RandomAccessibleInterval<DoubleType>) img, 1, 0); final IntervalView<DoubleType> opr = ops.transform().rotateView((RandomAccessibleInterval<DoubleType>) img, 1, 0); assertEquals(img.min(1), il2.min(0)); assertEquals(img.max(1), il2.max(0)); assertEquals(img.min(0), -il2.max(1)); assertEquals(img.max(0), -il2.min(1)); for (int i = 0; i < il2.numDimensions(); i++) { assertEquals(il2.max(i), opr.max(i)); assertEquals(il2.min(i), opr.min(i)); } } }
@Test public void test() { final long[] sizes = { 3, 4 }; final long n = LongStream.of( sizes ).reduce( 1, ( x, y ) -> x * y ); final long[] data = new long[ ( int ) n ]; for ( int i = 0; i < n; i++ ) { data[ i ] = i; } final RandomAccessibleInterval< LongType > source = ArrayImgs.longs( data, sizes ); final RandomAccess< LongType > sourceRA = source.randomAccess(); final RandomAccessibleInterval< LongType > actual = Views.rotate( source, 0, 1 ); final RandomAccess< LongType > actualRA = actual.randomAccess(); // check each value matches with their rotated counterparts for ( int i = 0; i < sizes[ 0 ]; i++ ) { for ( int j = 0; j < sizes[ 1 ]; j++ ) { sourceRA.setPosition( new long[] { i, j } ); actualRA.setPosition( new long[] { -j, i } ); assertEquals( sourceRA.get().get(), actualRA.get().get() ); } } // check to make sure the bounds are the same assertEquals( source.min( 0 ), actual.min( 1 ) ); assertEquals( source.max( 0 ), actual.max( 1 ) ); assertEquals( source.min( 1 ), -actual.max( 0 ) ); assertEquals( source.max( 1 ), -actual.min( 0 ) ); }