Skip to content

Instantly share code, notes, and snippets.

@ctrueden
Last active August 1, 2018 04:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctrueden/35c9873c2a1cc49388a5f310928fe2bb to your computer and use it in GitHub Desktop.
Save ctrueden/35c9873c2a1cc49388a5f310928fe2bb to your computer and use it in GitHub Desktop.
Read OME metadata using SCIFIO
#@ ImageJ ij
#@ File file
import io.scif.config.SCIFIOConfig;
import io.scif.config.SCIFIOConfig.ImgMode;
import io.scif.ome.OMEMetadata
// Open and display a file as a cell image.
config = new SCIFIOConfig().imgOpenerSetImgModes(ImgMode.CELL)
dataset = ij.scifio().datasetIO().open(file.getAbsolutePath(), config)
ij.ui().show(dataset)
// Extract metadata from a file opened in this manner.
globalMeta = dataset.getProperties().get("scifio.metadata.global")
imageMeta = dataset.getProperties().get("scifio.metadata.image")
// --OR-- We can read _only_ the metadata from a file without opening pixels.
//globalMeta = ij.scifio().initializer().parseMetadata(file.getAbsolutePath())
// Convert globalMeta above to omeMeta
omeMeta = new OMEMetadata(ij.context())
ij.scifio().translator().translate(globalMeta, omeMeta, true)
// Access some metadata from the OME trove. The below
// is just a small example of what the OME API provides.
omexml = omeMeta.getRoot()
iCount = omexml.getInstrumentCount()
for (iIndex = 0; iIndex < iCount; iIndex++) {
println("Instrument #" + iIndex + ":")
println("\tID = " + omexml.getInstrumentID(iIndex))
oCount = omexml.getObjectiveCount(iIndex)
for (oIndex = 0; oIndex < oCount; oIndex++) {
println("\tObjective #" + oIndex + ":")
println("\t\tID = " + omexml.getObjectiveID(iIndex, oIndex))
println("\t\tLensNA = " + omexml.getObjectiveLensNA(iIndex, oIndex))
println("\t\tModel = " + omexml.getObjectiveModel(iIndex, oIndex))
println("\t\tManufacturer = " + omexml.getObjectiveManufacturer(iIndex, oIndex))
}
}
@imagejan
Copy link

imagejan commented Jul 4, 2018

I also get a No supported format found when trying with an lsm file:

io.scif.FormatException: E:\[...]\image1.lsm: No supported format found.

@ctrueden
Copy link
Author

ctrueden commented Aug 1, 2018

For MSR files, this is because the SCIFIO OBFReader is taking precedence over Bio-Formats. But unfortunately, the SCIFIO OBFReader does not handle all MSR files successfully. The issue could be solved by addressing scifio/scifio-bf-compat#12.

I was not able to duplicate the LSM issue with the 2chZT.lsm sample from https://loci.wisc.edu/software/sample-data. Does this particular LSM file open successfully with Bio-Formats?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment