Java源码示例:net.imglib2.img.cell.CellImgFactory
示例1
@Test
public void testImageFactory() {
final Dimensions dim = new FinalDimensions(10, 10, 10);
@SuppressWarnings("unchecked")
final Img<DoubleType> arrayImg = (Img<DoubleType>) ops.run(
CreateImgFromDimsAndType.class, dim, new DoubleType(),
new ArrayImgFactory<DoubleType>());
final Class<?> arrayFactoryClass = arrayImg.factory().getClass();
assertEquals("Image Factory: ", ArrayImgFactory.class, arrayFactoryClass);
@SuppressWarnings("unchecked")
final Img<DoubleType> cellImg = (Img<DoubleType>) ops.run(
CreateImgFromDimsAndType.class, dim, new DoubleType(),
new CellImgFactory<DoubleType>());
final Class<?> cellFactoryClass = cellImg.factory().getClass();
assertEquals("Image Factory: ", CellImgFactory.class, cellFactoryClass);
}
示例2
@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());
}
示例3
protected ImgFactory<? extends NativeType<?>> selectImgFactory(final SlideBook6MetaData meta) {
int[] dims = meta.imageSize(0);
long maxNumPixels = dims[0];
maxNumPixels *= dims[1];
maxNumPixels *= dims[2];
String s = "Maximum number of pixels in any view: n=" + Long.toString(maxNumPixels) +
" px ";
if (maxNumPixels < Integer.MAX_VALUE) {
IOFunctions.println(s + "< " + Integer.MAX_VALUE + ", using ArrayImg.");
return new ArrayImgFactory<FloatType>();
} else {
IOFunctions.println(s + ">= " + Integer.MAX_VALUE + ", using CellImg.");
return new CellImgFactory<FloatType>(256);
}
}
示例4
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;
}
示例5
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);
}
示例6
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;
}
示例7
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;
}
示例8
public static Parameters getParameters()
{
final GenericDialogPlus gd = new GenericDialogPlus( "Resave dataset as TIFF" );
if ( defaultPath == null )
defaultPath = LoadParseQueryXML.defaultXMLfilename;
PluginHelper.addSaveAsFileField( gd, "Select new XML", defaultPath, 80 );
gd.addChoice( "ImgLib2_data_container", StackList.imglib2Container, StackList.imglib2Container[ defaultContainer ] );
gd.addCheckbox( "Lossless compression of TIFF files (ZIP)", defaultCompress );
gd.addMessage( "Use ArrayImg if -ALL- input views are smaller than ~2048x2048x500 px (2^31 px), or if the\n" +
"program throws an OutOfMemory exception while processing. CellImg is slower, but more\n" +
"memory efficient and supports much larger file sizes only limited by the RAM of the machine.",
new Font( Font.SANS_SERIF, Font.ITALIC, 11 ) );
gd.showDialog();
if ( gd.wasCanceled() )
return null;
final Parameters params = new Parameters();
params.xmlFile = gd.getNextString();
if ( !params.xmlFile.endsWith( ".xml" ) )
params.xmlFile += ".xml";
params.compress = defaultCompress = gd.getNextBoolean();
defaultPath = LoadParseQueryXML.defaultXMLfilename = params.xmlFile;
if ( ( defaultContainer = gd.getNextChoiceIndex() ) == 0 )
params.imgFactory = new ArrayImgFactory< FloatType >();
else
params.imgFactory = new CellImgFactory< FloatType >();
return params;
}
示例9
protected ImgFactory< ? extends NativeType< ? > > selectImgFactory( final LightSheetZ1MetaData meta )
{
long maxNumPixels = 0;
for ( int a = 0; a < meta.numAngles(); ++a )
{
final int[] dim = meta.imageSizes().get( a );
long n = 1;
for ( int d = 0; d < dim.length; ++d )
{
n *= (long)dim[ d ];
if ( dim[ d ] <= 0 )
{
IOFunctions.println( "Dimensions couldn't be read from metadata, using CellImg(256)." );
return new CellImgFactory< FloatType >( 256 );
}
}
maxNumPixels = Math.max( n, maxNumPixels );
}
int smallerLog2 = (int)Math.ceil( Math.log( maxNumPixels ) / Math.log( 2 ) );
String s = "Maximum number of pixels in any view: n=" + maxNumPixels +
" (2^" + (smallerLog2-1) + " < n < 2^" + smallerLog2 + " px), ";
if ( smallerLog2 <= 31 )
{
IOFunctions.println( s + "using ArrayImg." );
return new ArrayImgFactory< FloatType >();
}
else
{
IOFunctions.println( s + "using CellImg(256)." );
return new CellImgFactory< FloatType >( 256 );
}
}
示例10
public < T extends ComplexType< T > & NativeType < T > > ImgFactory< T > getImgFactory( final T type )
{
final ImgFactory< T > imgFactory;
if ( this.getImgType() == 0 )
imgFactory = new ArrayImgFactory< T >();
else if ( this.getImgType() == 1 )
imgFactory = new ImagePlusImgFactory< T >();
else
imgFactory = new CellImgFactory<T>( 256 );
return imgFactory;
}
示例11
@Override
public ImgFactory<T> calculate() {
return (dims == null || Intervals.numElements(dims) <= Integer.MAX_VALUE)
? new ArrayImgFactory<>() : new CellImgFactory<>();
}
示例12
@Override
public SlideBook6ImgLoader fromXml(
final Element elem, File basePath,
final AbstractSequenceDescription<?, ?, ?> sequenceDescription )
{
try
{
final File path = loadPath( elem, DIRECTORY_TAG, basePath );
final String masterFile = XmlHelpers.getText( elem, MASTER_FILE_TAG );
final String container = XmlHelpers.getText( elem, IMGLIB2CONTAINER_PATTERN_TAG );
final ImgFactory< FloatType > imgFactory;
if ( container == null )
{
System.out.println( "WARNING: No Img implementation defined in XML, using ArrayImg." );
// if no factory is defined we define an ArrayImgFactory
imgFactory = new ArrayImgFactory< FloatType >();
}
else
{
if ( container.toLowerCase().contains( "cellimg" ) )
{
imgFactory = new CellImgFactory< FloatType >( 256 );
}
else if ( container.toLowerCase().contains( "arrayimg" ) )
{
imgFactory = new ArrayImgFactory< FloatType >();
}
else if ( container.toLowerCase().contains( "planarimg" ) )
{
imgFactory = new PlanarImgFactory< FloatType >();
}
else
{
// if factory is unknown we define an ArrayImgFactory
imgFactory = new ArrayImgFactory< FloatType >();
System.out.println( "WARNING: Unknown Img implementation defined in XML:'" + container + "', using ArrayImg." );
}
}
return new SlideBook6ImgLoader( new File( path, masterFile ), imgFactory, sequenceDescription );
}
catch ( final Exception e )
{
throw new RuntimeException( e );
}
}
示例13
@Override
public LightSheetZ1ImgLoader fromXml(
final Element elem, File basePath,
final AbstractSequenceDescription<?, ?, ?> sequenceDescription )
{
try
{
final File path = loadPath( elem, DIRECTORY_TAG, basePath );
final String masterFile = XmlHelpers.getText( elem, MASTER_FILE_TAG );
final String container = XmlHelpers.getText( elem, IMGLIB2CONTAINER_PATTERN_TAG );
final ImgFactory< FloatType > imgFactory;
if ( container == null )
{
System.out.println( "WARNING: No Img implementation defined in XML, using ArrayImg." );
// if no factory is defined we define an ArrayImgFactory
imgFactory = new ArrayImgFactory< FloatType >();
}
else
{
if ( container.toLowerCase().contains( "cellimg" ) )
{
imgFactory = new CellImgFactory< FloatType >( 256 );
}
else if ( container.toLowerCase().contains( "arrayimg" ) )
{
imgFactory = new ArrayImgFactory< FloatType >();
}
else if ( container.toLowerCase().contains( "planarimg" ) )
{
imgFactory = new PlanarImgFactory< FloatType >();
}
else
{
// if factory is unknown we define an ArrayImgFactory
imgFactory = new ArrayImgFactory< FloatType >();
System.out.println( "WARNING: Unknown Img implementation defined in XML:'" + container + "', using ArrayImg." );
}
}
return new LightSheetZ1ImgLoader( new File( path, masterFile ), imgFactory, sequenceDescription );
}
catch ( final Exception e )
{
throw new RuntimeException( e );
}
}
示例14
@Override
public T fromXml( final Element elem, final File basePath, final AbstractSequenceDescription< ?, ?, ? > sequenceDescription )
{
try
{
File path = loadPath( elem, DIRECTORY_TAG, basePath );
String fileNamePattern = XmlHelpers.getText( elem, FILE_PATTERN_TAG );
int layoutTP = XmlHelpers.getInt( elem, LAYOUT_TP_TAG );
int layoutChannels = XmlHelpers.getInt( elem, LAYOUT_CHANNEL_TAG );
int layoutIllum = XmlHelpers.getInt( elem, LAYOUT_ILLUMINATION_TAG );
int layoutAngles = XmlHelpers.getInt( elem, LAYOUT_ANGLE_TAG );
final String container = XmlHelpers.getText( elem, IMGLIB2CONTAINER_PATTERN_TAG );
ImgFactory< FloatType > imgFactory;
if ( container == null )
{
System.out.println( "WARNING: No Img implementation defined, using ArrayImg." );
// if no factory is defined we define an ArrayImgFactory
imgFactory = new ArrayImgFactory< FloatType >();
}
else
{
if ( container.toLowerCase().contains( "cellimg" ) )
{
imgFactory = new CellImgFactory< FloatType >( 256 );
}
else if ( container.toLowerCase().contains( "arrayimg" ) )
{
imgFactory = new ArrayImgFactory< FloatType >();
}
else if ( container.toLowerCase().contains( "planarimg" ) )
{
imgFactory = new PlanarImgFactory< FloatType >();
}
else
{
// if factory is unknown we define an ArrayImgFactory
imgFactory = new ArrayImgFactory< FloatType >();
System.out.println( "WARNING: Unknown Img implementation '" + container + "', using ArrayImg." );
}
}
return createImgLoader( path, fileNamePattern, imgFactory, layoutTP, layoutChannels, layoutIllum, layoutAngles, sequenceDescription );
}
catch ( final Exception e )
{
throw new RuntimeException( e );
}
}
示例15
@Override
public boolean parseAdditionalParameters( final GenericDialog gd )
{
defaultFFTImgType = gd.getNextChoiceIndex();
if ( defaultFFTImgType == 0 )
computeFactory = new ArrayImgFactory< FloatType >();
else if ( defaultFFTImgType == 1 )
computeFactory = new ImagePlusImgFactory< FloatType >();
else
computeFactory = new CellImgFactory< FloatType >( 256 );
saveMemory = defaultSaveMemory = gd.getNextBoolean();
defaultIterationType = gd.getNextChoiceIndex();
if ( defaultIterationType == 0 )
iterationType = PSFTYPE.OPTIMIZATION_II;
else if ( defaultIterationType == 1 )
iterationType = PSFTYPE.OPTIMIZATION_I;
else if ( defaultIterationType == 2 )
iterationType = PSFTYPE.EFFICIENT_BAYESIAN;
else //if ( defaultIterationType == 3 )
iterationType = PSFTYPE.INDEPENDENT;
defaultWeightType = gd.getNextChoiceIndex();
if ( defaultWeightType == 0 )
weightType = WeightType.PRECOMPUTED_WEIGHTS;
else if ( defaultWeightType == 1 )
weightType = WeightType.VIRTUAL_WEIGHTS;
else if ( defaultWeightType == 2 )
weightType = WeightType.NO_WEIGHTS;
else
weightType = WeightType.WEIGHTS_ONLY;
osemspeedupIndex = defaultOSEMspeedupIndex = gd.getNextChoiceIndex();
numIterations = defaultNumIterations = (int)Math.round( gd.getNextNumber() );
debugMode = defaultDebugMode = gd.getNextBoolean();
adjustBlending = defaultAdjustBlending = gd.getNextBoolean();
useTikhonovRegularization = defaultUseTikhonovRegularization = gd.getNextBoolean();
lambda = defaultLambda = gd.getNextNumber();
blockSizeIndex = defaultBlockSizeIndex = gd.getNextChoiceIndex();
computationTypeIndex = defaultComputationTypeIndex = gd.getNextChoiceIndex();
extractPSFIndex = defaultExtractPSF = gd.getNextChoiceIndex();
displayPSF = defaultDisplayPSF = gd.getNextChoiceIndex();
return true;
}