Skip to content, Skip to search

Changes

ImgLib2 Examples

85 bytes removed, 16:43, 9 January 2015
Update documentation and code snippets for ImgLib2 stable release
All examples presented on this page are always entire classes including a main method to run them. Simply copying them into your favorite editor (e.g. the [[Script Editor]]) and compile & run them. The required Java libraries (jar files) are part of Fiji and can be found in ''Fiji.app/jars/'':
* imglib2.jar (the core)* imglib2-algorithms.jar algorithm (algorithms implemented in ImgLib2)* imglib2-algorithmsalgorithm-gpl.jar (GPL-licensed algorithms implemented in ImgLib2)* imglib2-io.jar scifio (input/output using Bio-Formats)* imglib2-ij.jar (the ImageJ interaction)* imglib2-realtransforms.jar realtransform (for example 8)* ij.jar (ImageJ 1.x core, used for display)* mpicbg.jar (for RealSum in example 3b)
and ''Fiji.app/plugins/'':
* loci_tools.jar bioformats_plugins (OME [[Bio-Formats]])
Alternately, you can access the examples from the {{GitHub|org=imglib|repo=imglib-tutorials|label=ImgLib Git repository}}. After cloning the ImgLib source code, open the ''imglib2/examples'' project in your favorite IDE. See [[Developing_Imglib]] for further details.
== Example 1 - Opening, creating and displaying images ==
<source lang="java">
import ij.ImageJ;
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.img.Img;
import net.imglib2.img.display.imagej.ImageJFunctions;
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;
import net.imglib2.type.numeric.real.FloatType;
import net.imglib2.view.Views;
<source lang="java">
import ij.ImageJ;
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;
import net.imglib2.Cursor;
import net.imglib2.RandomAccess;
import net.imglib2.img.cell.CellImgFactory;
import net.imglib2.img.display.imagej.ImageJFunctions;
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;
import net.imglib2.type.Type;
import net.imglib2.type.numeric.real.FloatType;
'''{{GitHub|org=imglib|repo=imglib-tutorials|source=Example3a1.java|label=Example3a1.java}}'''
<source lang="java">
 
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;
import java.util.Iterator;
import net.imglib2.RandomAccess;
import net.imglib2.img.Img;
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;
import net.imglib2.type.NativeType;
import net.imglib2.type.Type;
'''{{GitHub|org=imglib|repo=imglib-tutorials|source=Example3a3.java|label=Example3a3.java}}'''
<source lang="java">
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;
import net.imglib2.Cursor;
import net.imglib2.IterableInterval;
import net.imglib2.Point;
import net.imglib2.img.Img;
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;
import net.imglib2.type.NativeType;
import net.imglib2.type.Type;
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;
import net.imglib2.ExtendedRandomAccessibleInterval;
import net.imglib2.FinalInterval;
import net.imglib2.RandomAccessible;
import net.imglib2.outofbounds.OutOfBoundsConstantValueFactory;
import net.imglib2.type.numeric.real.FloatType;
import net.imglib2.view.ExtendedRandomAccessibleInterval;
import net.imglib2.view.Views;
<source lang="java">
import ij.ImageJ;
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;
import net.imglib2.Cursor;
import net.imglib2.FinalRealInterval;
import net.imglib2.interpolation.randomaccess.NLinearInterpolatorFactory;
import net.imglib2.interpolation.randomaccess.NearestNeighborInterpolatorFactory;
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;
import net.imglib2.type.Type;
import net.imglib2.type.numeric.real.FloatType;
// create the output image
Img< T > output = factory.create( pixelSize, Utilsource.realRandomAccess().getTypeFromRealRandomAccessget( source ) );
// cursor to iterate over all pixels
import net.imglib2.FinalInterval;
import net.imglib2.IterableRealInterval;
import net.imglib2.KDTree;
import net.imglib2.Point;
import net.imglib2.RandomAccessible;
import net.imglib2.RealInterval;
import net.imglib2.RealPoint;
import net.imglib2.RealPointSampleList;
import net.imglib2.RealRandomAccessible;
import net.imglib2.algorithm.gauss.Gauss;
import net.imglib2.collection.KDTree;
import net.imglib2.collection.RealPointSampleList;
import net.imglib2.img.Img;
import net.imglib2.img.array.ArrayImgFactory;
import net.imglib2.img.display.imagej.ImageJFunctions;
import net.imglib2.interpolation.neighborsearch.NearestNeighborInterpolatorFactoryNearestNeighborSearchInterpolatorFactory;
import net.imglib2.neighborsearch.NearestNeighborSearch;
import net.imglib2.neighborsearch.NearestNeighborSearchOnKDTree;
// make it into RealRandomAccessible using nearest neighbor search
RealRandomAccessible< FloatType > realRandomAccessible =
Views.interpolate( search, new NearestNeighborInterpolatorFactoryNearestNeighborSearchInterpolatorFactory< FloatType >() );
// convert it into a RandomAccessible which can be displayed
import net.imglib2.Interval;
import net.imglib2.IterableRealInterval;
import net.imglib2.KDTree;
import net.imglib2.RandomAccessible;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.RealInterval;
import net.imglib2.RealPoint;
import net.imglib2.RealPointSampleList;
import net.imglib2.RealRandomAccess;
import net.imglib2.RealRandomAccessible;
import net.imglib2.collection.KDTree;
import net.imglib2.collection.RealPointSampleList;
import net.imglib2.img.Img;
import net.imglib2.img.display.imagej.ImageJFunctions;
import net.imglib2.interpolation.neighborsearch.InverseDistanceWeightingInterpolatorFactory;
import net.imglib2.interpolation.neighborsearch.NearestNeighborInterpolatorFactoryNearestNeighborSearchInterpolatorFactory;
import net.imglib2.interpolation.randomaccess.NLinearInterpolatorFactory;
import net.imglib2.neighborsearch.KNearestNeighborSearch;
// make it into RealRandomAccessible using nearest neighbor search
RealRandomAccessible< T > realRandomAccessible = Views.interpolate( search,
new NearestNeighborInterpolatorFactoryNearestNeighborSearchInterpolatorFactory< T >() );
// convert it into a RandomAccessible which can be displayed
}
</source>
 
[[Category:ImgLib]]
[[Category:Tutorials]]
Bureaucrat, emailconfirmed, incoming, administrator, uploaders
11,833
edits