Saving single dimension axis Metadata with SCIFIO

Dear all,

I’m trying to save a tiff image to disk with custom metadata. Suppose that the last axis of the image are one in dimension. It appears that SCIFIO skips all those axis and assumes that this image is XY. Should this be considered a bug? Or is there a workaround for this?

    String source = "/home/masoud/Documents/SampleImages/XYTZC.tif";
    long[] dim = { 200, 200, 1, 1, 1 };
    Img<FloatType> img = new ArrayImgFactory<>(new FloatType()).create(dim);

    io.scif.formats.TIFFFormat.Metadata metadata = new io.scif.formats.TIFFFormat.Metadata();
    metadata.createImageMetadata(1);

    ImageMetadata imageMetadata = metadata.get(0);
    imageMetadata.setBitsPerPixel(FormatTools.getBitsPerPixel(FormatTools.FLOAT));
    imageMetadata.setFalseColor(true);
    imageMetadata.setPixelType(FormatTools.FLOAT);
    imageMetadata.setPlanarAxisCount(2);
    imageMetadata.setLittleEndian(false);
    imageMetadata.setIndexed(false);
    imageMetadata.setInterleavedAxisCount(0);
    imageMetadata.setThumbnail(false);
    imageMetadata.setOrderCertain(true);

    imageMetadata.addAxis(Axes.X, dim[0]);
    imageMetadata.addAxis(Axes.Y, dim[1]);
    imageMetadata.addAxis(Axes.TIME, dim[2]);
    imageMetadata.addAxis(Axes.Z, dim[3]);
    imageMetadata.addAxis(Axes.CHANNEL, dim[4]);

    ImgSaver saver = new ImgSaver();
    io.scif.formats.TIFFFormat.Writer<io.scif.formats.TIFFFormat.Metadata> writer = new io.scif.formats.TIFFFormat.Writer<>();
    writer.setContext(saver.context());
    writer.setMetadata(metadata);
    writer.setDest(source, new SCIFIOConfig());

    saver.saveImg(writer, img);

    Reader<io.scif.formats.TIFFFormat.Metadata> reader = new Reader<>();
    reader.setContext(saver.context());
    reader.setSource(source);
    ImageMetadata diskMetadata = reader.getMetadata().get(0);

    // This shows only xy exist!
    diskMetadata.getAxes();
2 Likes

Hi @Masoudas, thanks for posting the example! I would also expect singleton dimensions to be kept since the metadata specifies them. Here is an issue addressing this as well. Ping @hinerm

2 Likes

Well at least for the time being, and for pom-scijava-27.0.1 that I decided to use, this is not the case, i.e,
singletons are lost.

In any case, I look forward to the release of the new version of the library!