pyimagej
pyimagej copied to clipboard
Add axis convention handling to conversion functions
Numpy and matplotlib have limited axis handling capabilities when it comes to plotting. There is no way to specify a custom axis, such as XYCT vs XYTC, except by manually plotting it with foreknowledge of the axis.
In addition, numpy indexing is in row-major form (ZYX) which is reversed from Java (XYZ). However, as an exception, python plotting libraries assume that the image is RGB if the last channel is 3-dimensional. E.g. YXC or ZYXC. This complicates conversion back and forth between ImageJ and Numpy, as ImageJ opens RGB as XYZC, and so you can't simply reverse the axis order if you want to make the numpy image directly plotable.
The pyimagej conversion functions from_java and to_java should have some way of specifying channel conventions, and the view function should plot that convention correctly. This is particularly important in cases where ops/filters alter the axis order, which can quickly cause unintended errors.
@ctrueden suggests some form of hint variable or other way of passing through Metadata, but the implementation and edge-case handling needs to be determined.
I think we should invert the dimension order by default when going between ImgLib2 and NumPy. And we need the API to support customizable ordering during conversion as well.
See also imageio/imageio#382 and xarray.
This issue has been mentioned on Image.sc Forum. There might be relevant details there:
https://forum.image.sc/t/napari-should-i-reorder-the-dimensions-of-an-array-created-via-ij-py-from-java/53436/1
Aaxis handling conventions are fully resolved with #151, as well as explained in the tutorials, and customizable with individual conversions via the optional dim_order keyword arg, as implemented in #238 and part of the PyImageJ 1.4.0 release.