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 ); }
/** * Create an {@link ArrayImgFactory} if an image of the requested * <code>targetSize</code> could be held in an {@link ArrayImg}. Otherwise * return a {@link CellImgFactory} with as large as possible cell size. * * @param targetSize * size of image that the factory should be able to create. * @param type * type of the factory. * @return an {@link ArrayImgFactory} or a {@link CellImgFactory}. */ public static < T extends NativeType< T > > ImgFactory< T > getArrayOrCellImgFactory( final Dimensions targetSize, final T type ) { if ( Intervals.numElements( targetSize ) <= Integer.MAX_VALUE ) 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 ); }
/** * Create an {@link ArrayImgFactory} if an image of the requested * <code>targetSize</code> could be held in an {@link ArrayImg}. Otherwise * return a {@link CellImgFactory} with as large as possible cell size. * * @param targetSize * size of image that the factory should be able to create. * @param type * type of the factory. * @return an {@link ArrayImgFactory} or a {@link CellImgFactory}. */ public static < T extends NativeType< T > > ImgFactory< T > getArrayOrCellImgFactory( final Dimensions targetSize, final T type ) { if ( Intervals.numElements( targetSize ) <= Integer.MAX_VALUE ) 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 ); }
/** * Create an {@link ArrayImgFactory} if an image of the requested * <code>targetSize</code> could be held in an {@link ArrayImg}. Otherwise * return a {@link CellImgFactory} with cell size * <code>targetCellSize</code> (or as large as possible if * <code>targetCellSize</code> is too large). * * @param targetSize * size of image that the factory should be able to create. * @param targetCellSize * if a {@link CellImgFactory} is created, what should be the * cell size. * @param type * type of the factory. * @return an {@link ArrayImgFactory} or a {@link CellImgFactory}. */ public static < T extends NativeType< T > > ImgFactory< T > getArrayOrCellImgFactory( final Dimensions targetSize, final int targetCellSize, final T type ) { if ( Intervals.numElements( targetSize ) <= Integer.MAX_VALUE ) return new ArrayImgFactory<>( type ); final int cellSize; if ( Math.pow( targetCellSize, targetSize.numDimensions() ) <= Integer.MAX_VALUE ) cellSize = targetCellSize; else cellSize = ( int ) Math.pow( Integer.MAX_VALUE / type.getEntitiesPerPixel().getRatio(), 1.0 / targetSize.numDimensions() ); return new CellImgFactory<>( type, cellSize ); }
/** * Create an {@link ArrayImgFactory} if an image of the requested * <code>targetSize</code> could be held in an {@link ArrayImg}. Otherwise * return a {@link CellImgFactory} with cell size * <code>targetCellSize</code> (or as large as possible if * <code>targetCellSize</code> is too large). * * @param targetSize * size of image that the factory should be able to create. * @param targetCellSize * if a {@link CellImgFactory} is created, what should be the * cell size. * @param type * type of the factory. * @return an {@link ArrayImgFactory} or a {@link CellImgFactory}. */ public static < T extends NativeType< T > > ImgFactory< T > getArrayOrCellImgFactory( final Dimensions targetSize, final int targetCellSize, final T type ) { if ( Intervals.numElements( targetSize ) <= Integer.MAX_VALUE ) return new ArrayImgFactory<>( type ); final int cellSize; if ( Math.pow( targetCellSize, targetSize.numDimensions() ) <= Integer.MAX_VALUE ) cellSize = targetCellSize; else cellSize = ( int ) Math.pow( Integer.MAX_VALUE / type.getEntitiesPerPixel().getRatio(), 1.0 / targetSize.numDimensions() ); return new CellImgFactory<>( type, cellSize ); }
if (Math.pow(2, type.getBitsPerPixel() / type.getEntitiesPerPixel().getRatio()) < img.size()) { throw new RuntimeException("Cannot write histogram with type " + type.getClass());