@SuppressWarnings( { "unchecked", "rawtypes" } ) @Override public < S > ImgFactory< S > imgFactory( final S type ) throws IncompatibleTypeException { if ( NativeType.class.isInstance( type ) ) return new CellImgFactory( ( NativeType ) type, defaultCellDimensions ); throw new IncompatibleTypeException( this, type.getClass().getCanonicalName() + " does not implement NativeType." ); }
@SuppressWarnings( { "unchecked", "rawtypes" } ) @Override public < S > ImgFactory< S > imgFactory( final S type ) throws IncompatibleTypeException { if ( NativeType.class.isInstance( type ) ) return new CellImgFactory( ( NativeType ) type, defaultCellDimensions ); throw new IncompatibleTypeException( this, type.getClass().getCanonicalName() + " does not implement NativeType." ); }
@Override public ImgFactory<T> calculate() { return (dims == null || Intervals.numElements(dims) <= Integer.MAX_VALUE) ? new ArrayImgFactory<>() : new CellImgFactory<>(); }
@Override public <T extends RealType<T> & NativeType<T>> Dataset create(final T type, final long[] dims, final String name, final AxisType[] axes, final boolean virtual) { final ImgFactory<T> imgFactory; if (virtual) imgFactory = new CellImgFactory<>(type); else imgFactory = new PlanarImgFactory<>(type); return create(imgFactory, dims, name, axes); }
/** * Convenience method for creating an appropriate storage img: * {@link ArrayImg} if size is less than {@link Integer#MAX_VALUE}, * {@link CellImg} otherwise. */ private static < T extends NativeType< T > & RealType< T > > Img< T > createAppropriateOneDimensionalImage( final long size, final T t ) { final long[] dim = new long[] { 1, size }; return size > Integer.MAX_VALUE ? new CellImgFactory<>( t, Integer.MAX_VALUE ).create( dim ) : new ArrayImgFactory<>( t ).create( dim ); }
static < T extends NativeType< T > > ImgFactory< T > getImgFactory( final Dimensions targetsize, final double[][] halfkernels, final T type ) { if ( canUseArrayImgFactory( targetsize, halfkernels ) ) return new ArrayImgFactory< T >(); final int cellSize = ( int ) Math.pow( Integer.MAX_VALUE / type.getEntitiesPerPixel(), 1.0 / targetsize.numDimensions() ); return new CellImgFactory< T >( cellSize ); } }
static < T extends NativeType< T > > ImgFactory< T > getImgFactory( final Dimensions targetsize, final double[][] halfkernels, final T type ) { if ( canUseArrayImgFactory( targetsize, halfkernels ) ) return new ArrayImgFactory<>( type ); final int cellSize = ( int ) Math.pow( Integer.MAX_VALUE / type.getEntitiesPerPixel().getRatio(), 1.0 / targetsize.numDimensions() ); return new CellImgFactory<>( type, cellSize ); }
protected static ImgFactory< ComplexFloatType > getFFTFactory( final Img< ? extends RealType< ? > > img ) { try { return img.factory().imgFactory( new ComplexFloatType() ); } catch ( final IncompatibleTypeException e ) { if ( img.size() > Integer.MAX_VALUE / 2 ) return new CellImgFactory< ComplexFloatType >( 1024 ); return new ArrayImgFactory< ComplexFloatType >(); } }
protected static ImgFactory< ComplexFloatType > getFFTFactory( final Img< ? extends RealType< ? > > img ) { try { return img.factory().imgFactory( new ComplexFloatType() ); } catch (IncompatibleTypeException e) { if ( img.size() > Integer.MAX_VALUE / 2 ) return new CellImgFactory<ComplexFloatType>( 1024 ); return new ArrayImgFactory< ComplexFloatType >(); } } }
public static enum ImgDataType { VIRTUAL, CACHED, PRECOMPUTED }; public static String[] imgDataTypeChoice = new String[]{ "Virtual", "Cached", "Precompute Image" };
private < T extends NativeType< T > > void testDefaultCellSize( final T type ) { final int defaultCellSize = 43; final int[] expectedCellDims = { 43, 43, 43, 43 }; final CellImgFactory< T > factory = new CellImgFactory<>( type, defaultCellSize ); final long[] dimension = { 100, 80, 4, 3 }; final CellImg< T, ? > img = factory.create( dimension ); final int[] cellDims = new int[ dimension.length ]; img.getCellGrid().cellDimensions( cellDims ); assertArrayEquals( expectedCellDims, cellDims ); }
@Before public void setUp() { cellDimensions = new int[] { 8, 16, 5, 2 }; dimensions = new long[] { 20, 37, 12, 33 }; img = new CellImgFactory<>( new FloatType(), cellDimensions ).create( dimensions ); }
protected static ImgFactory< ComplexFloatType > getFFTFactory( final Img< ? extends RealType< ? > > img ) { try { return img.factory().imgFactory( new ComplexFloatType() ); } catch ( final IncompatibleTypeException e ) { if ( img.size() > Integer.MAX_VALUE / 2 ) return new CellImgFactory<>( new ComplexFloatType(), 1024 ); return new ArrayImgFactory<>( new ComplexFloatType() ); } }
private < T extends NativeType< T > > void testDefaultCellDimensions( final T type ) { final int[] defaultCellDims = { 6, 8, 5, 3 }; final int[] expectedCellDims = defaultCellDims.clone(); final CellImgFactory< T > factory = new CellImgFactory<>( type, defaultCellDims ); final long[] dimension = { 100, 80, 4, 3 }; final CellImg< T, ? > img = factory.create( dimension ); final int[] cellDims = new int[ dimension.length ]; img.getCellGrid().cellDimensions( cellDims ); assertArrayEquals( expectedCellDims, cellDims ); }
@SuppressWarnings("unchecked") @Test public void testImageFactory() { final Dimensions dim = new FinalDimensions( 10, 10, 10 ); assertEquals("Labeling Factory: ", ArrayImgFactory.class, ((Img<?>) ((ImgLabeling<String, ?>) ops.run( DefaultCreateImgLabeling.class, dim, null, new ArrayImgFactory<IntType>())).getIndexImg()).factory().getClass()); assertEquals("Labeling Factory: ", CellImgFactory.class, ((Img<?>) ((ImgLabeling<String, ?>) ops.run( DefaultCreateImgLabeling.class, dim, null, new CellImgFactory<IntType>())).getIndexImg()).factory().getClass()); }
@Test public void testCopyToCellContainerWithDestIteration() { final CellImg< IntType, ? > cellImg = new CellImgFactory<>( new IntType(), new int[] { 2, 7, 4 } ).create( dimensions ); copyWithDestIteration( intImg, cellImg ); assertArrayEquals( intData, getImgAsInts( cellImg ) ); }
public CellImg<ByteType, ?> generateByteTestCellImg(final boolean fill, final int[] cellDims, final long... dims) { final CellImg<ByteType, ?> img = new CellImgFactory<ByteType>(cellDims) .create(dims, new ByteType()); if (fill) { final Cursor<ByteType> c = img.cursor(); while (c.hasNext()) c.next().set((byte) pseudoRandom()); } return img; }
@Test public void testCopyToCellContainerWithSourceIteration() { final CellImg< IntType, ? > cellImg = new CellImgFactory<>( new IntType(), new int[] { 2, 7, 4 } ).create( dimensions ); copyWithSourceIteration( intImg, cellImg ); assertArrayEquals( intData, getImgAsInts( cellImg ) ); }
@Test public void equalIterationOrder() { final Img< FloatType > img2 = new CellImgFactory<>( new FloatType(), cellDimensions ).create( dimensions ); assertTrue( img2.iterationOrder().equals( img.iterationOrder() ) ); assertTrue( img.iterationOrder().equals( img2.iterationOrder() ) ); final Img< FloatType > img3 = new CellImgFactory<>( new FloatType(), 9 ).create( dimensions ); assertFalse( img3.iterationOrder().equals( img.iterationOrder() ) ); assertFalse( img.iterationOrder().equals( img3.iterationOrder() ) ); final Img< FloatType > img4 = new ArrayImgFactory<>( new FloatType() ).create( dimensions ); assertFalse( img4.iterationOrder().equals( img.iterationOrder() ) ); assertFalse( img.iterationOrder().equals( img4.iterationOrder() ) ); } }
public CellImg<ByteType, ?> generateByteTestCellImg(final boolean fill, final long... dims) { final CellImg<ByteType, ?> img = new CellImgFactory<ByteType>().create(dims, new ByteType()); if (fill) { final Cursor<ByteType> c = img.cursor(); while (c.hasNext()) c.next().set((byte) pseudoRandom()); } return img; }