ImageJ Viewer and SCIFIO Metadata

Dear all,

I’m trying to write an image with custom SCIFIO metadata, as shown in the code below. The most important thing here is to label each axis, so that they can be used later for visualization. The problem is that even though the metadata is written correctly, the default image viewer of ImageJ does not show the axis properly (always assumes all planes are z-plane). Moreover, the viewer in ImageJFunctions does not respect the axis assignment as well.

Any idea why this is the case? Should I use other writers out there?

@tpietzsch
@ctrueden

Img<UnsignedShortType> img = new ArrayImgFactory<>(new UnsignedShortType()).create(10,10,1, 10, 10);
     
        io.scif.formats.TIFFFormat.Metadata metadata = new io.scif.formats.TIFFFormat.Metadata();
        metadata.createImageMetadata(1);

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

        imageMetadata.addAxis(Axes.X, img.dimension(0));
        imageMetadata.addAxis(Axes.Y, img.dimension(1));
        imageMetadata.addAxis(Axes.CHANNEL, img.dimension(2));
        imageMetadata.addAxis(Axes.Z, img.dimension(3));
        imageMetadata.addAxis(Axes.TIME, img.dimension(4));
        

        File path = new File("/home/masoud/Documents/SampleImages/Img.tif");
        path.delete();
        path.createNewFile();
        
        Writer<io.scif.formats.TIFFFormat.Metadata> writer = new Writer<>();        
        writer.setContext(scifio.context());
        writer.setMetadata(metadata);
        writer.setDest(path.getPath(), new SCIFIOConfig());
        
        
        ImgSaver saver = new ImgSaver();

        saver.saveImg(writer, img);

Here’s the metadata of the image written to the disk by the way:

ImageDescription: SCIFIO=0.37.3
axes=X,Y,Channel,Z,Time
lengths=10,10,1,10,10
scales=1.0,1.0,1.0,1.0,1.0
units=null,null,null,null,null
bitsPerPixel=16
images=100
channels=1
slices=10
frames=10
hyperstack=true
mode=composite
unit=null

Software: SCIFIO

@Masoudas Did you try opening the TIFF afterward using SCIFIO as well? I.e.: File › Import › Image…? By default, File › Open… uses the ImageJ1 logic, which does not understand SCIFIO-style metadata. See also:

I’m not sure what you mean by “the viewer in ImageJFunctions”—are you using ij.io().open(myTiffFile) or ij.scifio().datasetIO().open(myTiffFile) to obtain a Dataset? If so, that uses SCIFIO to read it. Otherwise, ImageJ1 might be used.

Thanks for the helpful reply.

So essentially, I have to check on a case by case base to see which viewer is compatible with the metadata.

Can SCIFIO interpret the metadata of ImageJ1 image? What about that of omero tiff?

Yes, SCIFIO understands the ImageJ1-style metadata block.

SCIFIO also understands OME-TIFF via the io.scif:scifio-bf-compat plugin, which is included with Fiji.

1 Like