ImagePlus display swaps channels and frames


When I try to Convert a randomaccessibleinterval img to an ImagePlus by either


ImageJFunctions.wrapFloat(img, " ")

using net.imglib2 functions, the output ImagePlus always has channels and frames swapped even though in the input image those properties were set correctly.

Is there a fix for this without running a Macro to swap the channels and frames back?

The default dimension order for ImageJ1 images (i.e. ImagePlus) is XYCZT, and this is assumed when you wrap any ImgLib2 object, since Img and RandomAccessibleInterval don’t carry any axis information.

If you want to specify axes, you’ll have to use an ImageJ2 ImgPlus:

imgPlus = new ImgPlus(img, name, axes);

Thanks, I am now searching for specifying the axis keyword, its datatype etc. I want it to be ‘XYT’, usually specifying axes like this works in python. I have to figure out how to do this in ImageJ2.

Got it, AxisType[] axisTypes = new AxisType[]{ Axes.X, Axes.Y, Axes.TIME };. Thanks.

1 Like

Ok, the axis order is retained till I try to display the image using ImageJFunctions. Referring to an old thread : Imglib2 java axes, there they had an ImagePlus to start with but in my case I have a RandomaccessibleInterval to start with which I then save as an ImgPlus with correct axes order :

AxisType[] axisTypes = new AxisType[] { Axes.X, Axes.Y, Axes.TIME };

ImgPlus<FloatType> newimp = new ImgPlus<FloatType>(probImg, “Curvature Display”, axisTypes);

But I loose the axis information if I use, is setDimensions() function in imp the only way to get a proper display then?

Hi @kapoorlab,

The issue is that the code that you’re using to display above ( doesn’t know about the axis metadata that you introduced. Even more, once you do newIp.getImg() the object that you get doesn’t have the metadata anymore.

The answer is to use the UIService to display your images since it knows how to treat you metadata.
And to use your ImgPlus directly. See:

// @Dataset data
// @UIService ui

// in my example, data is [X,Y,Z]
// this displays it as [X,Y,Z] data )

// change the axis information to [X,Y,T]
AxisType[] axInfo = [ Axes.X, Axes.Y, Axes.TIME ]
myImgPlus = new ImgPlus( data, "myImgPlus",  axInfo )
// this displays it as [X,Y,T] myImgPlus )

// this displays it as [X,Y,C], since 
// ImageJFunctions treats 'data' as a "plain" imglib2 object
// and goes to default axis ordering data, "ij1-ImagePlus" );



Thanks for your help John but this would require a major change in the current plugin structure that I have. I remember seeing some tutorials about this:
But for now I will go for a quickfix to set the dimensions in the old way using setdimensions.

I will keep this for later.