Get scifio image meta data with Fiji (ImageJ2 plugin)

Hi all,
I am developing an ImageJ2 plugin and need the slice labels of an image stack.
The method below works fine when run with the main method of the plugin in Eclipse as a Maven project. But when compiled as a jar file and copied to the fiji Plugins folder, a NullPointerException is thrown at line:

MetaTable metaTable = metaData.getTable();

import java.util.Map;
import io.scif.DefaultImageMetadata;
import io.scif.MetaTable;

@Parameter(type = ItemIO.INPUT)
private Dataset dataset;


Map<String, Object> prop = dataset.getProperties();
DefaultImageMetadata metaData = (DefaultImageMetadata) prop.get("scifio.metadata.image");
MetaTable metaTable = metaData.getTable();
sliceLabels = (String[]) metaTable.get("SliceLabels");

Can anybody help me?
Best wishes,
Helmut

Hi Helmut,

The error suggests that the dataset might not have been opened with SCIFIO. How did you open the dataset?

By default SCIFIO is not turned on in Fiji. You need to activate it under Edit>Options>ImageJ2… with the checkbox. Then File>Open will default to SCIFIO. You can check if your image was opened with SCIFIO in several ways. One easy way is to have a look at Image>Show Info… It should say SCIFIO at the top.

If this seems like it might be the issue, then it might be helpful to test out what you want to do in a groovy script. Then you could check if the properties actually contains a “scifio.metadata.image” key and that the contents of “SliceLabels” has what you want. For example using the script below:

#@ Dataset dataset

import java.util.Map;
import io.scif.DefaultImageMetadata;
import io.scif.MetaTable;

Map<String, Object> prop = dataset.getProperties()
println(prop.keySet())

DefaultImageMetadata metaData = (DefaultImageMetadata) prop.get("scifio.metadata.image")
MetaTable metaTable = metaData.getTable()
sliceLabels = (String[]) metaTable.get("SliceLabels")
println(sliceLabels)

There could also be a configuration problem with the plugin, but it is hard to tell without a full example. In any case, just write back and I can certainly generate more ideas. Hope this helps!

Karl

1 Like

Many thanks Karl, your suggestion solved that issue!! Now, I get the SCIFIO slice labels in my plugin.
Now, I found out following:

  • SCIFIO deactivated: slice labels are shown at the top of the image display frame and are listed with Image>Show Info, but cannot be read out in my plugin.

  • SCIFIO activated: slice labels are not shown in the image display and are not listed with Image>Show Info, but can be read out in my plugin.

  • Image size is shown in both cases.

Obviously, Fiji has implemented other methods to read out meta data. Do you have any hint or example, how Fiji gets this meta data?

BTW, I think you did not copy your Groovy script example in your reply.

Many thanks again,
Helmut

That’s a bug, likely in the synchronization between ImageJ2 Dataset (which is loaded by SCIFIO) and ImageJ1 ImagePlus (which is displayed in the legacy UI).

I filed an issue here:


The slice labels should be accessible in the same way, no matter if you use SCIFIO or not to open your image data.

To work around the issue, you can ask for an @Parameter ImagePlus instead of an @Parameter Dataset, and then use the methods provided by ImageJ1, e.g. imp.getStack().getSliceLabels().

1 Like

Dear @imagejan,
Thanks for picking up this issue.

Best wishes,
Helmut