Imglib2 java axes

Hello,

Is there somewhere a java example of how to change axes in imglib2?

I am opening an 2d (500x500) time-series (50) dataset using

final ImagePlus imp = new Opener().openImage( file.getAbsolutePath() );
final Img img = ImageJFunctions.wrap( imp );

And it correctly reads the correct number of dimensions: 500x500x50
But using ImageJFunctions.show( img ) to show it, it shows that 50 is the channel dimension rather than the time dimension.

2 Likes

Unfortunately, yes. Wrapping it as an imglib2 Img loses the meta-information. Imglib2 doesn’t deal with axes semantics at all. ImageJFunctions.show() just uses the default (XYCZT?) order. It returns an ImagePlus though, which you can use the setDimensions(nChannels, nSlices, nFrames) to make it correct.

3 Likes

@Christian_Tischer you can keep the axis information by using an ImgPlus (in image-common) wherever possible.

The following Groovy script illustrates the loss of axis information when going via ImgLib2’s ImageJFunctions:

#@ ImagePlus imp
#@ ImgPlus img

import net.imglib2.img.display.imagej.ImageJFunctions
import net.imagej.ImgPlus

im = ImgPlus.wrap(ImageJFunctions.wrap( imp ))

println "*** via ImgLib2 ***"
im.numDimensions().times {
	println im.axis(it).type()
}

println "*** ImgPlus ***"
img.numDimensions().times {
	println img.axis(it).type()
}

which, when run on the Bat Cochlea Volume sample image, prints:

*** via ImgLib2 ***
X
Y
Unknown
*** ImgPlus ***
X
Y
Z
3 Likes

Thanks for the tip! I just had a look at the code and it looks like ImgPlus does assume the image being an interval, is it? We are working on writing image registration code in imglib2 and from what I think I learned so far we at least in-between need image classes that are not an interval, e.g. RealRandomAccessible, so we would loose the calibration and axes information at this steps, is this correct or am I wrong? (I am still a total imglib2 newbie!!)