Page 1 of 1

Extracting MetaData with ImageJ Macro Extensions

PostPosted: Fri May 15, 2015 1:25 pm
by davemason
I've been trying to access the metadata of a multidimensional LSM file in an Fiji macro. My basic code looks something like this (trimmed for brevity):

Code: Select all
run("Bio-Formats Macro Extensions");
filePath = File.openDialog("Choose a file");
Ext.setId(filePath);

Ext.getMetadataValue("Channel Name #05",val);
print(val);


But Val always returns zero. I'm making the assumption that the key/value pairs as seen in the "Show Info" dialog are even the right ones to be addressing (cf. the OME XML metadata).

Any pointers appreciated, sorry if this belongs on the ImageJ list.

Thanks!

Dave Mason

Re: Extracting MetaData with ImageJ Macro Extensions

PostPosted: Tue May 19, 2015 9:06 am
by davemason
I can't believe I missed this but of course you can use the built in ImageJ macro functions to read out the metadata.

If anyone's interested, if you want to extract the values of metadata in the form:
Code: Select all
ChannelName #01 = 420
ChannelName #02 = 430
ChannelName #03 = 440
ChannelName #04 = 450

you can do something like this:
Code: Select all
infoString=getMetadata("Info");
chanPos=indexOf(infoString,"ChannelName #");
chanNum=substring(infoString,chanPos+18,chanPos+21);
print("Value = "+chanNum);

You then need to loop using indexOf starting beyond the first one to get the next value.

Definitely belonged on the ImageJ list, but I would still be interested in the nuances of doing this with Bioformats.

Dave

Re: Extracting MetaData with ImageJ Macro Extensions

PostPosted: Tue May 19, 2015 8:37 pm
by bramalingam
Hi,

Please check the examples in the following link (section : Macros and plugins),
https://www.openmicroscopy.org/site/sup ... rs/imagej/

To view the total list of Bio-formats macro extensions functions,
(Select) ImageJ/Fiji-->Plugins-->Bio-Formats-->Bio-Formats Macro Extensions.

Hope that helps.

Best,
Balaji

Re: Extracting MetaData with ImageJ Macro Extensions

PostPosted: Wed May 20, 2015 8:13 am
by davemason
Hi Balaji,

Thanks for your response. I had already looked over the macro examples and also found the list of commands. It's fairly obvious how to extract the dimensions with:

Ext.getImageCount(imageCount),
Ext.getSizeX(sizeX)
Ext.getSizeY(sizeY)
Ext.getSizeC(sizeC)
... &c

Unfortunately that doesn't help with accessing other metadata. What is unclear to me is if I have metadata that look like this:
Code: Select all
<OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2015-01" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2015-01 http://www.openmicroscopy.org/Schemas/OME/2015-01/ome.xsd">
<Experimenter ID="Experimenter:0" UserName="LSM User"/>

---trimmed ---

<DetectorSettings ID="Detector:0:0"/>
<LightPath/>
<Channel Color="-1" ID="Channel:0:1" Name="430" SamplesPerPixel="1">
<LightPath/>

How to I access (for example) the value "430" (towards the bottom) that represents the name of the first channel? Presumably using something like the code in the original post?

Re: Extracting MetaData with ImageJ Macro Extensions

PostPosted: Mon May 25, 2015 3:30 pm
by bramalingam
Hi,

The Bio-Formats macro extensions are slightly limited on this regard, and have opened a ticket for the same,
https://trac.openmicroscopy.org/ome/ticket/12898

You have been added to the CC list, and will get notified once the ticket gets updated.

Best,
Balaji

Re: Extracting MetaData with ImageJ Macro Extensions

PostPosted: Mon May 25, 2015 9:14 pm
by davemason
Great, thanks for that. I just wanted to make sure I wasn't missing something obvious with getMetadataValue()

Re: Extracting MetaData with ImageJ Macro Extensions

PostPosted: Mon Oct 08, 2018 10:34 am
by kostermw
Hi,
After a lot of trial and error I succeeded in retrieving metadata from a czi file (LSM880). The difficulty was to find the correct field names, but you can get these by opening one of your files (interactively) and checking the "Display metadata" checkbox. What you get is a full list of fields (keys) that were retrieved including their values. E.g I found;
Information|Image|Channel|Wavelength #1 488
Now, these field descriptions can be used to retrieve the values (don't forget the quotes in you code);

run("Bio-Formats Macro Extensions");
run("Bio-Formats","open=" + myFilename + " autoscale color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT" );
Ext.setId(myFilename);
Ext.getMetadataValue("Information|Image|Channel|Wavelength #1", myChannel_1_WaveLength);
print("Channel 1 Wavelength = ["+myChannel_1_WaveLength+"]");

Re: Extracting MetaData with ImageJ Macro Extensions

PostPosted: Tue Oct 09, 2018 10:48 am
by dgault
Thank you for sharing your solution, Im sure it will be useful for others with the same issue. That is currently the best way to retrieve the data, though as you said for non core metadata values you will have to know the specific String naming. I will keep the existing ticket open as extending the macro functions in the future is likely a better long term solution.