How to get ALL metadata from Bio-Formats importer in macro

I’d like to retrieve all metadata as text from a .lif file, as I need certain data in there.

Running the Bio-Formats Importer macro command using the “display_metadata” flag, I can open the lif file and I now know the function to obtain the sub_series names, but how do I access the whole ‘raw’ metadata text? By accident and forgotten how, one time I obtained a text in a window then called Original Metadata, that has all the data I need, and which I already can parse.

Importing the .lif file as virtual stack with NO image boxes ticked, I still get the first image opened, with its sub-series metadata only. I can tell the difference between the whole metadata and subseries data as the whole metadata lines start with the name of a subseries (if applicable), followed by a space and then the rest of the key. E.g. the (accidentally obtained once) original metadata reads
while the metadata in the text window "Original Metadata " subseries text window that opens is

The “Bio-Formats Macro Extension” macro doesn’t seem to list the function name to open the entire metadata as text.


Hi @eljonco, if you change the macro language to python then the below code should allow you to read an image and get either the series metadata or the global metadata:

file = "/path/to/file/myfile.tiff"

from loci.formats import ImageReader
from loci.formats import MetadataTools
reader = ImageReader()
omeMeta = MetadataTools.createOMEXMLMetadata()
seriesCount = reader.getSeriesCount()
globalMetadata = reader.getSeriesMetadata()
globalMetadata = reader.getGlobalMetadata()
1 Like

Thanks for your efforts @dgault. Unfortunately, all my other macro code is in ImageJ1 language, I don’t speak Py and the code you kindly offered is throwing me a few errors in my environment (quickly whipped up Java8 Fiji), which obviously I can’t handle.

I’ll keep investigating as because I once obtained the metadata required, there must be a way in ImageJ1 macro code.

To answer my own question: the option to read ONLY the metadata is hidden in the popup in the second step of the Bio-Formats import, ‘View stack with:’. Change the preset “Hyperstack” to “Metadata only”, which results in this recorded command:

run(“Bio-Formats Importer”, “open=filename.lif color_mode=Default display_metadata rois_import=[ROI manager] view=[Metadata only] stack_order=Default”);

1 Like