/** * Creates an image with randomized content * @param type Pixel type * @param dims Dimensions */ public < T extends NativeType< T > > Img< T > nextImage( final T type, final long... dims ) { final Img< T > result = new ArrayImgFactory<>( type ).create( dims ); return randomize( result ); }
@Override public ArrayImgFactory< T > factory() { return new ArrayImgFactory<>( linkedType ); }
@Override public ArrayImg< T, ? > create( final Dimensions dimensions ) { return create( Intervals.dimensionsAsLongArray( dimensions ) ); }
private < A extends ArrayDataAccess< A > > ArrayImg< T, A > create( final long[] dimensions, final T type, final NativeTypeFactory< T, A > typeFactory ) { final Fraction entitiesPerPixel = type.getEntitiesPerPixel(); final int numEntities = numEntitiesRangeCheck( dimensions, entitiesPerPixel ); final A data = ArrayDataAccessFactory.get( typeFactory ).createArray( numEntities ); final ArrayImg< T, A > img = new ArrayImg<>( data, dimensions, entitiesPerPixel ); img.setLinkedType( typeFactory.createLinkedType( img ) ); return img; }
@Override public ArrayImgFactory< T > factory() { return new ArrayImgFactory<>( linkedType ); }
@Override public ArrayImg<T, A> createOutput(final ArrayImg<T, A> input) { // NB: Workaround for ArrayImgFactory not overriding create(Dimensions, T). final long[] dims = new long[ input.numDimensions() ]; input.dimensions( dims ); final ArrayImg<T, ?> copy = input.factory().create(dims, input.firstElement().createVariable()); // TODO: Find a way to guarantee the type. @SuppressWarnings("unchecked") final ArrayImg<T, A> typedCopy = (ArrayImg<T, A>) copy; return typedCopy; }
/** * Creates an image with randomized content * @param type Pixel type * @param dims Dimensions */ public < T extends NativeType< T > > Img< T > nextImage( final T type, final long... dims ) { final Img< T > result = new ArrayImgFactory<>( type ).create( dims ); return randomize( result ); }
@SuppressWarnings( { "unchecked", "rawtypes" } ) @Override public < S > ImgFactory< S > imgFactory( final S type ) throws IncompatibleTypeException { if ( type instanceof NativeType ) return new ArrayImgFactory( (NativeType) type ); throw new IncompatibleTypeException( this, type.getClass().getCanonicalName() + " does not implement NativeType." ); }
@Override public ArrayImg< T, ? > copy() { final ArrayImg< T, ? > copy = factory().create( dimension ); final ArrayCursor< T > source = this.cursor(); final ArrayCursor< T > target = copy.cursor(); while ( source.hasNext() ) target.next().set( source.next() ); return copy; }
static private final <R extends NumericType<R>, T extends NativeType<T> & NumericType<T>> Img<T> create(final Img<R> img, final T type, final Converter<R, T> converter) { final Img< T > iimg = new ArrayImgFactory<>( type ).create( img ); integrateInto(img, iimg, type, converter); return iimg; }
@SuppressWarnings("unchecked") public static ArrayImg< FloatType, ? > openAs32BitArrayImg( final File file ) { return (ArrayImg< FloatType, ? >)openAs32Bit( file, new ArrayImgFactory< FloatType >() ); }
@Override public ArrayImg< T, ? > copy() { final ArrayImg< T, ? > copy = factory().create( dimension ); final ArrayCursor< T > source = this.cursor(); final ArrayCursor< T > target = copy.cursor(); while ( source.hasNext() ) target.next().set( source.next() ); return copy; }
@Override public final NativeImgLabeling< L, ? extends IntegerType< ? >> createEmptyOutput( final Labeling< L >[] src ) { long[] resDims = initConstants( src ); @SuppressWarnings( "unchecked" ) NativeImgLabeling< L, ? extends IntegerType< ? >> res = new NativeImgLabeling( new ArrayImgFactory().create( resDims, ( NativeType ) m_resType ) ); return res; }
@SuppressWarnings( { "unchecked", "rawtypes" } ) @Override public < S > ImgFactory< S > imgFactory( final S type ) throws IncompatibleTypeException { if ( type instanceof NativeType ) return new ArrayImgFactory( (NativeType) type ); throw new IncompatibleTypeException( this, type.getClass().getCanonicalName() + " does not implement NativeType." ); }
@Override public final NativeImgLabeling< L, ? extends IntegerType< ? >> createEmptyOutput( final Labeling< L >[] src ) { long[] resDims = initConstants( src ); @SuppressWarnings( "unchecked" ) NativeImgLabeling< L, ? extends IntegerType< ? >> res = new NativeImgLabeling( new ArrayImgFactory().create( resDims, ( NativeType ) m_resType ) ); return res; }
public ArrayImgLoader( final T type ) { opener = new ImgOpener(); factory = new ArrayImgFactory<>(); this.type = type; }