Skip to content, Skip to search

Changes

ImgLib2 Examples

190 bytes removed, 10:38, 18 November 2013
Example 1b - Opening an ImgLib2 image
<source lang="java">
import ij.ImageJ;
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;
import io.scif.img.ImgOptions;
import io.scif.img.ImgOptions.ImgMode;
import java.io.File;
import net.imglib2.exception.IncompatibleTypeException;
import net.imglib2.img.Img;
import net.imglib2.img.ImgFactory;
import net.imglib2.img.array.ArrayImgFactory;
import net.imglib2.img.cell.CellImgFactory;
import net.imglib2.img.display.imagej.ImageJFunctions;
import net.imglib2.io.ImgIOException;
import net.imglib2.io.ImgOpener;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;
/**
* Opens a file with SCIFIO's ImgOpener Bioformats as an ImgLib2 Img.
*/
public class Example1b
// Type is able to map the data into an java basic type array
public < T extends RealType< T > & NativeType< T > > Example1b()
throws ImgIOException, IncompatibleTypeException
{
// define the file to open
File file = new File( "DrosophilaWing.tif" );
String path = file.getAbsolutePath();
// open with create the ImgOpener and ImgOptions ImgOpener imgOpener = new ImgOpener using an ArrayImgFactory, here the return type will be(); // defined by the openerImgOptions imgOptions = new ImgOptions();  // the opener will ignore the Type of the ArrayImgFactoryopen with ImgOpener as an ArrayImg ImgFactory< ? > imgFactory = new ArrayImgFactory< T >imgOptions.setImgModes(ImgMode.ARRAY ); Img< T > image = new ImgOpener()imgOpener.openImg( file.getAbsolutePath()path, imgFactory imgOptions );
// display it via ImgLib using ImageJ
ImageJFunctions.show( image );
// open with ImgOpener as Float using a CellImgFactory, CellImg with FloatType // it will be opened as float // independent of the type of the image
// to enforce to open it as FloatType, an instance of FloatType has to be passed along
imgOptions.setImgModes( ImgMode.CELL ); Img< FloatType > imageFloat = new ImgOpener()imgOpener.openImg( file.getAbsolutePath()path, new CellImgFactory< FloatType >( 10 ), new FloatType() imgOptions );
// display it via ImgLib using ImageJ
}
public static void main( String[] args ) throws ImgIOException, IncompatibleTypeException
{
// open an ImageJ window
Bureaucrat, emailconfirmed, incoming, administrator, uploaders
11,833
edits