Why is getIndex present in ImageReader but not in ImageWriter?

I am using BioFormats to read and write to an image file.
When reading an image, I noticed that it is possible to calculate the plane that I want to read by using C, T and Z, like this:

int C = ...;
int T = ...;
int Z = ...;
ImageReader reader = new ImageReader();
int planeNumber = reader.getIndex(Z, C, T);
reader.openBytes(planeNumber, [...]);

However, I do not have the same luxury when writing an image.
Currently, the only way to do it is to manually input the information about Z, C, T:

int totalZ = ...;
int totalC = ...;
int totalT = ...;
String dimensionOrder = ...;
int planeNumber = FormatTools.getIndex(dimensionOrder, totalZ, totalC, totalT, Z, C, T);
ImageWriter writer = new ImageWriter();

// Populate necessary metadata, have some bytes to write to image...
writer.saveBytes(planeNumber, [...]);

In order to write bytes into an image, it is required anyways to insert the minimum required metadata, so the information about ZCT should already be available.

Given this, it is not clear to me why the getIndex method is not directly available to the ImageWriter interface, which would be both convenient and consistent.

Hi @IAL32, the reader.getIndex method is actually just making the same call to FormatTools.getIndex that you are making here for the writer. It makes sense when reading as you likely do not know the metadata values for the dimensions whereas when writing you should have those values. This could be a potential addition to the writer API though if it makes live easier. If you wanted to attempt to add the method you can open a PR against to bioformats/FormatWriter.java at 4112fefe16743306507d23d6f2e8f0b28d040f2d · ome/bioformats · GitHub and I would be happy to review it.

1 Like