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))
}
}
@lhilbert
Copy link

lhilbert commented Jun 7, 2018

From running the script, I removed the full file paths on my hard drive, indicated by [...]

java.io.IOException: io.scif.img.ImgIOException: io.scif.FormatException: [...]/Dome_006.msr: No supported format found.
at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:135)
at io.scif.services.DatasetIOService$open.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at Script2.run(Script2.groovy:10)
at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(GroovyScriptEngine.java:303)
at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(GroovyScriptEngine.java:122)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:238)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: io.scif.img.ImgIOException: io.scif.FormatException: [...]/Dome_006.msr: No supported format found.
at io.scif.img.ImgOpener.createReader(ImgOpener.java:425)
at io.scif.img.ImgOpener.openImgs(ImgOpener.java:145)
at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:125)
... 17 more
Caused by: io.scif.FormatException: [...]/Dome_006.msr: No supported format found.
at io.scif.services.DefaultFormatService.getFormatList(DefaultFormatService.java:350)
at io.scif.services.DefaultFormatService.getFormat(DefaultFormatService.java:316)
at io.scif.services.DefaultInitializeService.initializeReader(DefaultInitializeService.java:88)
at io.scif.img.ImgOpener.createReader(ImgOpener.java:419)
... 19 more

@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