Last active
August 1, 2018 04:13
-
-
Save ctrueden/35c9873c2a1cc49388a5f310928fe2bb to your computer and use it in GitHub Desktop.
Read OME metadata using SCIFIO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@ 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)) | |
} | |
} |
I also get a No supported format found
when trying with an lsm
file:
io.scif.FormatException: E:\[...]\image1.lsm: No supported format found.
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
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