/** * 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 ); }
private CellGrid createCellGrid(final long[] dimensions, final Fraction entitiesPerPixel) { CellImgFactory.verifyDimensions(dimensions); final int n = dimensions.length; final int[] defaultDims = new int[dimensions.length]; for (int d = 0; d < defaultDims.length; d++) { defaultDims[d] = dimensions[d] < defaultCellDimensions[d] ? // (int) dimensions[d] : defaultCellDimensions[d]; } final int[] cellDimensions = CellImgFactory.getCellDimensions( defaultDims, n, entitiesPerPixel); return new CellGrid(dimensions, cellDimensions); }
@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." ); }
private < A extends ArrayDataAccess< A > > CellImg< T, A > create( final long[] dimensions, final T type, final NativeTypeFactory< T, A > typeFactory ) { verifyDimensions( dimensions ); final int n = dimensions.length; final Fraction entitiesPerPixel = type.getEntitiesPerPixel(); final int[] cellDimensions = getCellDimensions( defaultCellDimensions, n, entitiesPerPixel ); final CellGrid grid = new CellGrid( dimensions, cellDimensions ); final long[] gridDimensions = new long[ grid.numDimensions() ]; grid.gridDimensions( gridDimensions ); final Cell< A > cellType = new Cell<>( new int[] { 1 }, new long[] { 1 }, null ); final ListImg< Cell< A > > cells = new ListImg<>( gridDimensions, cellType ); final long[] cellGridPosition = new long[ n ]; final long[] cellMin = new long[ n ]; final int[] cellDims = new int[ n ]; final ListLocalizingCursor< Cell< A > > cellCursor = cells.localizingCursor(); while ( cellCursor.hasNext() ) { cellCursor.fwd(); cellCursor.localize( cellGridPosition ); grid.getCellDimensions( cellGridPosition, cellMin, cellDims ); final A data = ArrayDataAccessFactory.get( typeFactory ).createArray( ( int ) entitiesPerPixel.mulCeil( Intervals.numElements( cellDims ) ) ); cellCursor.set( new Cell<>( cellDims, cellMin, data ) ); } final CellImg< T, A > img = new CellImg<>( this, grid, cells, entitiesPerPixel ); img.setLinkedType( typeFactory.createLinkedType( img ) ); return img; }
@Override public CellImg< T, ? > create( final Dimensions dimensions ) { return create( Intervals.dimensionsAsLongArray( dimensions ) ); }
public CellImgFactory( final T type, final int... cellDimensions ) { super( type ); defaultCellDimensions = cellDimensions.clone(); verifyDimensions( defaultCellDimensions ); }
@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." ); }
private < A extends ArrayDataAccess< A > > CellImg< T, A > create( final long[] dimensions, final T type, final NativeTypeFactory< T, A > typeFactory ) { verifyDimensions( dimensions ); final int n = dimensions.length; final Fraction entitiesPerPixel = type.getEntitiesPerPixel(); final int[] cellDimensions = getCellDimensions( defaultCellDimensions, n, entitiesPerPixel ); final CellGrid grid = new CellGrid( dimensions, cellDimensions ); final long[] gridDimensions = new long[ grid.numDimensions() ]; grid.gridDimensions( gridDimensions ); final Cell< A > cellType = new Cell<>( new int[] { 1 }, new long[] { 1 }, null ); final ListImg< Cell< A > > cells = new ListImg<>( gridDimensions, cellType ); final long[] cellGridPosition = new long[ n ]; final long[] cellMin = new long[ n ]; final int[] cellDims = new int[ n ]; final ListLocalizingCursor< Cell< A > > cellCursor = cells.localizingCursor(); while ( cellCursor.hasNext() ) { cellCursor.fwd(); cellCursor.localize( cellGridPosition ); grid.getCellDimensions( cellGridPosition, cellMin, cellDims ); final A data = ArrayDataAccessFactory.get( typeFactory ).createArray( ( int ) entitiesPerPixel.mulCeil( Intervals.numElements( cellDims ) ) ); cellCursor.set( new Cell<>( cellDims, cellMin, data ) ); } final CellImg< T, A > img = new CellImg<>( this, grid, cells, entitiesPerPixel ); img.setLinkedType( typeFactory.createLinkedType( img ) ); return img; }
@Override public CellImg< T, ? > create( final Dimensions dimensions ) { return create( Intervals.dimensionsAsLongArray( dimensions ) ); }
@Deprecated public CellImgFactory( final int... cellDimensions ) { defaultCellDimensions = cellDimensions.clone(); verifyDimensions( defaultCellDimensions ); }
protected < T extends NativeType< T > > Img< T > instantiateImg( final long[] dim, final T type ) { Img< T > img; try { img = getImgFactory().imgFactory( type ).create( dim, type ); } catch ( Exception e1 ) { try { img = new CellImgFactory< T >( 256 ).create( dim, type ); } catch ( Exception e2 ) { img = null; } } return img; }
public void copyImages() { copyImages( new CellImgFactory<>( MultiViewDeconvolution.cellDim ) ); }
private CellGrid createCellGrid(final long[] dimensions, final Fraction entitiesPerPixel) { CellImgFactory.verifyDimensions(dimensions); final int n = dimensions.length; final int[] defaultDims = new int[dimensions.length]; for (int d = 0; d < defaultDims.length; d++) { defaultDims[d] = dimensions[d] < defaultCellDimensions[d] ? // (int) dimensions[d] : defaultCellDimensions[d]; } final int[] cellDimensions = CellImgFactory.getCellDimensions( defaultDims, n, entitiesPerPixel); return new CellGrid(dimensions, cellDimensions); }
public CellImgFactory( final T type, final int... cellDimensions ) { super( type ); defaultCellDimensions = cellDimensions.clone(); verifyDimensions( defaultCellDimensions ); }
@Override protected Img<T> getProcessingLine( final long sizeProcessLine ) { final Img<T> processLine; // try to use array if each individual line is not too long if ( sizeProcessLine <= Integer.MAX_VALUE ) { isArray = true; processLine = new ArrayImgFactory< T >().create( new long[]{ sizeProcessLine }, getProcessingType() ); } else { isArray = false; processLine = new CellImgFactory< T >( Integer.MAX_VALUE / 16 ).create( new long[]{ sizeProcessLine }, getProcessingType() ); } return processLine; }
public void copyUnnormalizedWeights() { copyUnnormalizedWeights( new CellImgFactory<>( MultiViewDeconvolution.cellDim ) ); }