ImageJFunctions.wrap does implicit Views.dropSingletonDimensions


It looks like that ImageJFunctions.wrap is smart and drops singleton dimensions during conversion (as seen in below example: 86x75x1x1x3 => 86x75x3). This is somehow nice, but it also makes it tricky to figure out in the resulting wrap image which dimension is which in terms of z, channel and time. Is there a better way to do this conversion?


Yes, I had the same problem. So there’s now a solution. You should use VirtualStackAdapter.wrap(), this will return an ImgPlus ( don’t confuse ImgPlus and ImagePlus they are very different). The ImgPlus is an imglib2 Img plus metadata about the axes etc…


Thanks, this is great!

I think it could be worth to also implement ImageJFunctions.wrapXYCZT( ImagePlus imp ), which would always return a 5D RandomAccessibleInterval with XYCZT dimension order.

The advantages would be

  • one would stay in pure imglib2 world without dependencies to ImgPlus
  • one could directly and simply use Views.hyperslice on the resulting 5D RandomAccessibleInterval to extract certain dimensions without the need to write code to check axes metadata.

What do you think? Maybe not worth it?

1 Like