We're Hiring!

Extracting MetaData with ImageJ Macro Extensions

Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats
Please note:
Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats

If you are having trouble with image files, there is information about reporting bugs in the Bio-Formats documentation. Please send us the data and let us know what version of Bio-Formats you are using. For issues with your code, please provide a link to a public repository, ideally GitHub.

Extracting MetaData with ImageJ Macro Extensions

Postby davemason » Fri May 15, 2015 1:25 pm

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
davemason
 
Posts: 47
Joined: Thu Mar 06, 2014 3:00 pm
Location: Liverpool, UK

Re: Extracting MetaData with ImageJ Macro Extensions

Postby davemason » Tue May 19, 2015 9:06 am

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
davemason
 
Posts: 47
Joined: Thu Mar 06, 2014 3:00 pm
Location: Liverpool, UK

Re: Extracting MetaData with ImageJ Macro Extensions

Postby bramalingam » Tue May 19, 2015 8:37 pm

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
User avatar
bramalingam
 
Posts: 70
Joined: Tue Jan 14, 2014 12:01 pm

Re: Extracting MetaData with ImageJ Macro Extensions

Postby davemason » Wed May 20, 2015 8:13 am

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?
davemason
 
Posts: 47
Joined: Thu Mar 06, 2014 3:00 pm
Location: Liverpool, UK

Re: Extracting MetaData with ImageJ Macro Extensions

Postby bramalingam » Mon May 25, 2015 3:30 pm

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
User avatar
bramalingam
 
Posts: 70
Joined: Tue Jan 14, 2014 12:01 pm

Re: Extracting MetaData with ImageJ Macro Extensions

Postby davemason » Mon May 25, 2015 9:14 pm

Great, thanks for that. I just wanted to make sure I wasn't missing something obvious with getMetadataValue()
davemason
 
Posts: 47
Joined: Thu Mar 06, 2014 3:00 pm
Location: Liverpool, UK

Re: Extracting MetaData with ImageJ Macro Extensions

Postby kostermw » Mon Oct 08, 2018 10:34 am

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+"]");
kostermw
 
Posts: 3
Joined: Fri Oct 05, 2018 9:01 pm

Re: Extracting MetaData with ImageJ Macro Extensions

Postby dgault » Tue Oct 09, 2018 10:48 am

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.
User avatar
dgault
Team Member
 
Posts: 208
Joined: Fri Aug 14, 2015 2:56 pm


Return to User Discussion [Legacy]

Who is online

Users browsing this forum: No registered users and 1 guest