@Override public RandomAccessibleInterval<T> calculate(List<? extends RandomAccessibleInterval<T>> input) { return Views.stack(stackAccessMode, input); }
@Override public RandomAccessibleInterval<T> calculate(List<? extends RandomAccessibleInterval<T>> input) { return Views.stack(input); }
@Override public CompositeIntervalView<T, RealComposite<T>> calculate(RandomAccessibleInterval<T> input) { List<RandomAccessibleInterval<T>> derivatives = new ArrayList<>(); for (int i = 0; i < derivativeFunctions.length; i++) { RandomAccessibleInterval<T> derivative = derivativeFunctions[i].calculate(input); derivatives.add(derivative); } RandomAccessibleInterval<T> stacked = Views.stack(derivatives); return Views.collapseReal(stacked); } }
/** * Create an (<em>n</em>+1)-dimensional {@link RandomAccessible} of an * <em>n</em>-dimensional {@link RandomAccessible} that maps the four * channels encoded in {@link ARGBType} into a dimension. The order * of the channels passed as arguments is preserved. The source is being * modified as expected by writing into the converted channels. * * @param source * @param channels 0 = alpha, 1 = red, 2 = green, 3 = blue * * @return a converted {@link RandomAccessibleInterval} whose * {@link Sampler Samplers} perform on-the-fly value conversion * into and from the corresponding channels of the original * {@link ARGBType}. */ final static public RandomAccessibleInterval< UnsignedByteType > argbChannels( final RandomAccessibleInterval< ARGBType > source, final int... channels ) { final ArrayList< RandomAccessibleInterval< UnsignedByteType > > hyperSlices = new ArrayList<>(); for ( final int channel : channels ) hyperSlices.add( argbChannel( source, channel ) ); return Views.stack( hyperSlices ); }
/** * Create an (<em>n</em>+1)-dimensional {@link RandomAccessible} of an * <em>n</em>-dimensional {@link RandomAccessible} that maps the four * channels encoded in {@link ARGBType} into a dimension. The order * of the channels passed as arguments is preserved. The source is being * modified as expected by writing into the converted channels. * * @param source * @param channels 0 = alpha, 1 = red, 2 = green, 3 = blue * * @return a converted {@link RandomAccessibleInterval} whose * {@link Sampler Samplers} perform on-the-fly value conversion * into and from the corresponding channels of the original * {@link ARGBType}. */ final static public RandomAccessibleInterval< UnsignedByteType > argbChannels( final RandomAccessibleInterval< ARGBType > source, final int... channels ) { final ArrayList< RandomAccessibleInterval< UnsignedByteType > > hyperSlices = new ArrayList<>(); for ( final int channel : channels ) hyperSlices.add( argbChannel( source, channel ) ); return Views.stack( hyperSlices ); }
/** * Compose a list of same {@link Interval} and same {@link Type} A * {@link RandomAccessibleInterval RandomAccessibleIntervals} into a * {@link RandomAccessibleInterval} of some target {@link Type} B using a * {@link Converter} from {@link Composite} of A to B. * * @param components * @param composer * @param targetType * @return */ final static public < A, B extends Type< B > > RandomAccessibleInterval< B > compose( final List< RandomAccessibleInterval< A > > components, final Converter< Composite< A >, B > composer, final B targetType ) { return convert( Views.collapse( Views.stack( components ) ), composer, targetType ); }
/** * Compose a list of same {@link Interval} and same {@link NumericType} A * {@link RandomAccessibleInterval RandomAccessibleIntervals} into a * {@link RandomAccessibleInterval} of some target {@link Type} B using a * {@link Converter} from {@link Composite} of A to B. * * @param components * @param composer * @param targetType * @return */ final static public < A extends NumericType< A >, B extends Type< B > > RandomAccessibleInterval< B > composeNumeric( final List< RandomAccessibleInterval< A > > components, final Converter< NumericComposite< A >, B > composer, final B targetType ) { return convert( Views.collapseNumeric( Views.stack( components ) ), composer, targetType ); }
/** * Compose a list of same {@link Interval} and same {@link Type} A * {@link RandomAccessibleInterval RandomAccessibleIntervals} into a * {@link RandomAccessibleInterval} of some target {@link Type} B using a * {@link Converter} from {@link Composite} of A to B. * * @param components * @param composer * @param targetType * @return */ final static public < A, B extends Type< B > > RandomAccessibleInterval< B > compose( final List< RandomAccessibleInterval< A > > components, final Converter< Composite< A >, B > composer, final B targetType ) { return convert( Views.collapse( Views.stack( components ) ), composer, targetType ); }
/** * Compose a list of same {@link Interval} and same {@link NumericType} A * {@link RandomAccessibleInterval RandomAccessibleIntervals} into a * {@link RandomAccessibleInterval} of some target {@link Type} B using a * {@link Converter} from {@link Composite} of A to B. * * @param components * @param composer * @param targetType * @return */ final static public < A extends NumericType< A >, B extends Type< B > > RandomAccessibleInterval< B > composeNumeric( final List< RandomAccessibleInterval< A > > components, final Converter< NumericComposite< A >, B > composer, final B targetType ) { return convert( Views.collapseNumeric( Views.stack( components ) ), composer, targetType ); }
/** * Compose a list of same {@link Interval} and same {@link RealType} A * {@link RandomAccessibleInterval RandomAccessibleIntervals} into a * {@link RandomAccessibleInterval} of some target {@link Type} B using a * {@link Converter} from {@link Composite} of A to B. * * @param components * @param composer * @param targetType * @return */ final static public < A extends RealType< A >, B extends Type< B > > RandomAccessibleInterval< B > composeReal( final List< RandomAccessibleInterval< A > > components, final Converter< RealComposite< A >, B > composer, final B targetType ) { return convert( Views.collapseReal( Views.stack( components ) ), composer, targetType ); }
/** * Compose a list of same {@link Interval} and same {@link RealType} A * {@link RandomAccessibleInterval RandomAccessibleIntervals} into a * {@link RandomAccessibleInterval} of some target {@link Type} B using a * {@link Converter} from {@link Composite} of A to B. * * @param components * @param composer * @param targetType * @return */ final static public < A extends RealType< A >, B extends Type< B > > RandomAccessibleInterval< B > composeReal( final List< RandomAccessibleInterval< A > > components, final Converter< RealComposite< A >, B > composer, final B targetType ) { return convert( Views.collapseReal( Views.stack( components ) ), composer, targetType ); }
@Override public CompositeIntervalView<T, RealComposite<T>> calculate(RandomAccessibleInterval<T> input) { List<RandomAccessibleInterval<T>> derivatives = new ArrayList<>(); for (int i = 0; i < derivativeComputers.length; i++) { RandomAccessibleInterval<T> derivative = createRAI.calculate(input); derivativeComputers[i].compute(input, derivative); for (int j = 0; j < derivativeComputers.length; j++) { RandomAccessibleInterval<T> out = createRAI.calculate(input); derivativeComputers[j].compute(derivative, out); derivatives.add(out); } } RandomAccessibleInterval<T> stackedDerivatives = Views.stack(derivatives); return Views.collapseReal(stackedDerivatives); }
hyperSlices.add( Views.hyperSlice( source, concatenationAxis, index ) ); final RandomAccessibleInterval< T > stacked = Views.stack( mode, hyperSlices ); return Views.moveAxis( stacked, stacked.numDimensions() - 1, concatenationAxis );
/** * Create an (<em>n</em>+1)-dimensional {@link RandomAccessible} of an * <em>n</em>-dimensional {@link RandomAccessible} that maps the four * channels encoded in {@link ARGBType} into a dimension. The source is * being modified as expected by writing into the converted channels. * * @param source * * @return a converted {@link RandomAccessibleInterval} whose * {@link Sampler Samplers} perform on-the-fly value conversion * into and from the corresponding channels of the original * {@link ARGBType}. */ final static public RandomAccessibleInterval< UnsignedByteType > argbChannels( final RandomAccessibleInterval< ARGBType > source ) { return Views.stack( argbChannel( source, 0 ), argbChannel( source, 1 ), argbChannel( source, 2 ), argbChannel( source, 3 ) ); }
/** * Create an (<em>n</em>+1)-dimensional {@link RandomAccessible} of an * <em>n</em>-dimensional {@link RandomAccessible} that maps the four * channels encoded in {@link ARGBType} into a dimension. The source is * being modified as expected by writing into the converted channels. * * @param source * * @return a converted {@link RandomAccessibleInterval} whose * {@link Sampler Samplers} perform on-the-fly value conversion * into and from the corresponding channels of the original * {@link ARGBType}. */ final static public RandomAccessibleInterval< UnsignedByteType > argbChannels( final RandomAccessibleInterval< ARGBType > source ) { return Views.stack( argbChannel( source, 0 ), argbChannel( source, 1 ), argbChannel( source, 2 ), argbChannel( source, 3 ) ); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void compute(final RandomAccessibleInterval<I> input, final IterableInterval<BitType> output) { final List<RandomAccessibleInterval<RealType>> listOfIntegralImages = new ArrayList<>(); for (final int order : requiredIntegralImages()) { final RandomAccessibleInterval<RealType> requiredIntegralImg = getIntegralImage(input, order); listOfIntegralImages.add(requiredIntegralImg); } // Composite image of integral images of order 1 and 2 final RandomAccessibleInterval<RealType> stacked = Views.stack( listOfIntegralImages); final RandomAccessibleInterval<? extends Composite<RealType>> compositeRAI = Views.collapse(stacked); final RandomAccessibleInterval<? extends Composite<RealType>> extendedCompositeRAI = removeLeadingZeros(compositeRAI); final NeighborhoodsIterableInterval<? extends Composite<RealType>> neighborhoods = shape.neighborhoodsSafe(extendedCompositeRAI); if (map == null) { map = (BinaryComputerOp) ops().op(Map.class, out(), in(), neighborhoods, filterOp); } map.compute(input, neighborhoods, output); }
@Test public void stackWithAccessModeTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType()); List<Img<DoubleType>> list = new ArrayList<>(); list.add(img); list.add(img); RandomAccessibleInterval<DoubleType> il2 = Views.stack(StackAccessMode.DEFAULT, list); RandomAccessibleInterval<DoubleType> opr = ops.transform().stackView(list, StackAccessMode.DEFAULT); assertEquals(il2.dimension(2), opr.dimension(2)); }
@Test public void defaultStackTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType()); List<Img<DoubleType>> list = new ArrayList<>(); list.add(img); list.add(img); RandomAccessibleInterval<DoubleType> il2 = Views.stack(list); RandomAccessibleInterval<DoubleType> opr = ops.transform().stackView(list); assertEquals(il2.dimension(2), opr.dimension(2)); }
private ImgPlus<UnsignedByteType> splitColorChannels(ImgPlus<ARGBType> input) { Img<ARGBType> colored = input.getImg(); RandomAccessibleInterval<UnsignedByteType> colorStack = Views.stack( Converters.argbChannel( colored, 1 ), Converters.argbChannel( colored, 2 ), Converters.argbChannel( colored, 3 ) ); ImgPlus<UnsignedByteType> result = new ImgPlus<>(ImgView.wrap(colorStack, new PlanarImgFactory<>()), input.getName()); int lastAxis = colored.numDimensions(); for (int i = 0; i < lastAxis; i++) result.setAxis(input.axis(i).copy(), i); result.setAxis(new DefaultLinearAxis(Axes.CHANNEL), lastAxis); return ImgPlusViews.moveAxis(result, lastAxis, 2); }
@Test public void testStacking() { // lets create a stack with every second plane of the input image, // works! final List< RandomAccessibleInterval< UnsignedByteType >> intervals = new ArrayList< RandomAccessibleInterval< UnsignedByteType > >(); for ( int d = 0; d < img.dimension( 2 ); d++ ) { if ( d % 2 == 0 ) intervals.add( Views.dropSingletonDimensions( Views.interval( img, new FinalInterval( new long[] { img.min( 0 ), img.min( 1 ), d }, new long[] { img.max( 0 ), img.max( 1 ), d } ) ) ) ); } // stack it! final RandomAccessibleInterval< UnsignedByteType > stack = Views.stack( intervals ); assertTrue( stack.numDimensions() == 3 ); assertTrue( intervals.size() == stack.dimension( 2 ) ); final Cursor< UnsignedByteType > stackC = Views.iterable( stack ).cursor(); while ( stackC.hasNext() ) { assertTrue( stackC.next().get() % 2 == 0 ); } } }