Difference between revisions of "How To Migrate Code From ImgLib To ImgLib2"
(Point out the ImgLib2 page more clearly.)
|Line 1:||Line 1:|
ImgLib2 is a major redesign of ImgLib, and [[
ImgLib2 is a major redesign of ImgLib, and [[much has changed]]. This page attempts to provide a "how-to" guide for bringing existing ImgLib1 code up to date with ImgLib2.
== Rename packages ==
== Rename packages ==
Revision as of 14:52, 22 April 2011
ImgLib2 is a major redesign of ImgLib, and much has changed. This page attempts to provide a "how-to" guide for bringing existing ImgLib1 code up to date with ImgLib2. It is intended as a "quick start" guide—for more details, see the Changes from ImgLib1 to ImgLib2 page.
All packages have changed from prefix "mpicbg.imglib" to "net.imglib2" to avoid a name clash, and to conform to convention (visit  if you don't believe us).
Hence, it is easiest to perform a global search and replace for all instances of the old string with the new. This holds for all renames listed below.
Some core packages have also changed further:
- mpicbg.imglib.image -> net.imglib2.img
The Image class has been replaced with Img. Many classes with "Image" in the name have thus been changed to "Img" instead:
- Image -> Img
- ImageFactory -> ImgFactory
- ImageOpener -> ImgOpener
All dimensional lengths are now long (and long) instead of int (and int). In addition, core methods for querying dimensional lengths have changed names:
- getNumDimensions() -> numDimensions()
- getDimension(int) -> dimension(int)
- getDimensions() -> dimensions(long)
For dimensions(long), note that it only populates an existing array. There is no method to allocate and return a new dimensional array. Instead, use the following code:
final long dims = new long[img.numDimensions()]; img.dimensions(dims);
Containers are now built in to the Img. For instance, PlanarImg (an implementation of Img) essentially replaces PlanarContainer. Essentially, ContainerFactory and ImageFactory have been combined into ImgFactory.
There were previously three types: Cursor, LocalizableCursor and LocalizableByDimCursor. This is still true, but the terminology has changed: a cursor can now be "localizable"—meaning you can tell where it is in the dimensional structure—and/or "positionable"—meaning you can move the cursor to somewhere else. Essentially, you have three kinds of cursors:
- img.cursor() – returns a Cursor without "read" or "write" access to the dimensional position. Use when you don't care where you are in the structure, and want the most efficient path.
- img.localizingCursor() – returns a Cursor with "read-only" access to the dimensional position. Use when you need to know where the cursor currently sits, but don't need to change the position other than normal iteration.
- img.randomAccess() – returns a RandomAccess with "read-write" access to the dimensional position. Use when you need to change the position.
Another way of looking at it is that Cursors are similar to InputStreams and must go forward, whereas RandomAccesses are similar to RandomAccessFiles and can seek back and forth at will.
If you were using RGBALegacyType, note that it has changed to ARGBType, but serves the same purpose.