Skip to content, Skip to search

Changes

How To Migrate Code From ImgLib To ImgLib2

7 bytes removed, 15:05, 2 September 2017
Add more code tags; use source tags as appropriate
In addition, core methods for querying dimensional lengths have changed names:
* <code>getNumDimensions()</code> → <code>numDimensions()</code>* <code>getDimension(int) </code> <code>dimension(int)</code>* <code>getDimensions() </code> <code>dimensions(long[])</code>
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:
<source lang="java">final long[] dims = new long[img.numDimensions()]; img.dimensions(dims);</source>
== Remove references to Container and ContainerFactory ==
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, the three kinds of cursors are now:
# <code>img.cursor() </code> – returns a Cursor with "read-only" access to the dimensional position which is calculated on demand which might be an expensive calculation. Use when you don't care where you are in the structure (or only sparsely need this information), and want the most efficient path.# <code>img.localizingCursor() </code> – returns a Cursor with "read-only" access to the dimensional position. Such Cursors track their position at each fwd() call and thus can calculate it more efficiently than the above. Use when you always or often need to know where the cursor currently sits, but don't need to change the position other than normal iteration.# <code>img.randomAccess() </code> – 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.
Here is an example:
<codesource lang="java"> ExtendedRandomAccessibleInterval< IntType, Img< IntType> > extendedInterval = new ExtendedRandomAccessibleInterval< IntType, Img< IntType > >( myIntImg, new OutOfBoundsMirrorFactory< IntType, Img< IntType > >( Boundary.DOUBLE ) ); RandomAccess< IntType > randomAccess = extendedInterval.randomAccess();</codesource>
== Rename RGBLegacyType to ARGBType ==
If you were using <code>RGBALegacyType</code>, note that it has changed to <code>ARGBType</code>, but serves the same purpose.
== Use net.imglib2.display.Projector instead of mpicbg.imglib.image.display.Display ==
The Display class and corresponding packages are no longer applicable to ImgLib2. Instead, create a Projector. See the [http://fiji.sc/cgi-bin/gitweb.cgi?p=imglib.git;a=blob;f=imglib2/ui/src/main/java/net/imglib2/ui/ImgPanel.java;hb=refs/heads/master ImgPanel] class in the imglib-ui project for an example.
== Additional issues ==
The RegionOfInterestCursor class is no longer available and its replacement is not yet in place. You'll need to work around this in the short term.
The <code>Image.clone() </code> method has been now named <code>Img.copy()</code>.
Bureaucrat, emailconfirmed, incoming, administrator, uploaders
12,248
edits