InsightSoftwareConsortium/ITKIOOMEZarrNGFF

ENH: Support different axis orders

tbirdso opened this issue · 1 comments

Current Behavior

After #43 ITKIOOMEZarrNGFF will support reading from OME-Zarr stores where spatial axes appear in the order z,y,x. For instance, the following are supported:

  • y,x
  • z,y,x
  • t,y,x
  • t,c,z,y,x
  • t,z,y,x,c
    etc.

OME-Zarr and ITK axis access conventions are reversed. A 3D ITK image represents data with x,y,z axes, where "x" is the fastest moving and "z" is the slowest moving image axis. A 3D OME-Zarr store with axes "z", "y", "x" equivalently represents data where "z" is the slowest moving image axis and 'x" is the fastest moving image axis.

EDIT: Note that the order of spatial axes is not explicitly enforced. In theory images with out-of-order spatial axes can be read out of order. However, spatial metadata in the resulting ITK image may similarly be out of order.

Requested Behavior

Allow the user to specify the order in which OME-Zarr axes should permute to map to ITK axes. Handle spatial metadata (direction, origin, spacing) accordingly.

For instance:

imageio = itk.OMEZarrNGFFImageIO.New()
imageio.SetNamedAxes(['x','y','z']) # equivalent to ITK default
# read, etc...

or:

imageio = itk.OMEZarrNGFFImageIO.New()
imageio.SetNamedAxes(['x','z','y'])
# read, etc...

NamedAxes should default to the expected ITK spatial axes, i.e. [x,y,z].

Enhancement 1

Allow the user to query what named axes are available and reconfigure accordingly.

image_reader.SetImageIO(imageio)
image_reader.SetFileName(filename)
image_reader.UpdateOutputInformation()
print(imageio.GetNamedAxes())    # ['x','t','angle',etc]

Enhancement 2

Consider mapping arbitrary axes to ITK dimensions:

imageio.SetNamedAxes(['t','angle','z'])
imageio.SetNamedIndex('x', 5)
imageio.SetNamedIndex('y',10)
# read, etc...

Metadata may get tricky under this general approach.

ITK's default order of axes is c,x,y,z,t. In OME-zarr specification, this is known as t,z,y,x,c order. This corresponds to identity direction matrix. Any other permutation corresponds to non-identity direction. I was suggesting that direction be set according the the axes order, so your described "enhancement 1".

Channel axis should be treated differently, as per #32.