use of loci.formats.services.OMEXMLService in project bioformats by openmicroscopy.
the class PrintTimestamps method main.
public static void main(String[] args) throws Exception {
// parse command line arguments
if (args.length < 1) {
System.err.println("Usage: java PrintTimestamps imageFile [seriesNo]");
System.exit(1);
}
String id = args[0];
int series = args.length > 1 ? Integer.parseInt(args[1]) : 0;
// enable debugging
// FormatReader.debug = true;
// create OME-XML metadata store of the latest schema version
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata meta = service.createOMEXMLMetadata();
// or if you want a specific schema version, you can use:
// IMetadata meta = service.createOMEXMLMetadata(null, "2009-02");
// meta.createRoot();
// create format reader
IFormatReader reader = new ImageReader();
reader.setMetadataStore(meta);
// initialize file
System.out.println("Initializing " + id);
reader.setId(id);
int seriesCount = reader.getSeriesCount();
if (series < seriesCount)
reader.setSeries(series);
series = reader.getSeries();
System.out.println("\tImage series = " + series + " of " + seriesCount);
printDimensions(reader);
printGlobalTiming(meta, series);
printTimingPerTimepoint(meta, series);
printTimingPerPlane(meta, series);
}
use of loci.formats.services.OMEXMLService in project bioformats by openmicroscopy.
the class ConvertToOmeTiff method main.
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.out.println("Usage: java ConvertToOmeTiff file1 file2 ...");
return;
}
ImageReader reader = new ImageReader();
OMETiffWriter writer = new OMETiffWriter();
for (int i = 0; i < args.length; i++) {
String id = args[i];
int dot = id.lastIndexOf(".");
String outId = (dot >= 0 ? id.substring(0, dot) : id) + ".ome.tif";
System.out.print("Converting " + id + " to " + outId + " ");
// record metadata to OME-XML format
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata omexmlMeta = service.createOMEXMLMetadata();
reader.setMetadataStore(omexmlMeta);
reader.setId(id);
// configure OME-TIFF writer
writer.setMetadataRetrieve(omexmlMeta);
writer.setId(outId);
// writer.setCompression("J2K");
// write out image planes
int seriesCount = reader.getSeriesCount();
for (int s = 0; s < seriesCount; s++) {
reader.setSeries(s);
writer.setSeries(s);
int planeCount = reader.getImageCount();
for (int p = 0; p < planeCount; p++) {
byte[] plane = reader.openBytes(p);
// write plane to output file
writer.saveBytes(p, plane);
System.out.print(".");
}
}
writer.close();
reader.close();
System.out.println(" [done]");
}
}
use of loci.formats.services.OMEXMLService in project bioformats by openmicroscopy.
the class DisplayHandler method displayOMEXML.
/**
* Displays OME-XML metadata in a tree in its own window.
*/
public XMLWindow displayOMEXML() throws FormatException, IOException {
if (!options.isShowOMEXML())
return null;
XMLWindow metaWindow = null;
metaWindow = new XMLWindow("OME Metadata - " + process.getIdName());
Exception exc = null;
try {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
metaWindow.setXML(service.getOMEXML(process.getOMEMetadata()));
WindowTools.placeWindow(metaWindow);
metaWindow.setVisible(true);
} catch (DependencyException e) {
exc = e;
} catch (ServiceException e) {
exc = e;
} catch (ParserConfigurationException e) {
exc = e;
} catch (SAXException e) {
exc = e;
}
if (exc != null)
throw new FormatException(exc);
// save reference to OME-XML window
xmlWindow = metaWindow;
return metaWindow;
}
use of loci.formats.services.OMEXMLService in project bioformats by openmicroscopy.
the class ImportProcess method createBaseReader.
/**
* Initializes an {@link loci.formats.IFormatReader}
* according to the current configuration.
*/
private void createBaseReader() throws FormatException, IOException {
if (options.isLocal() || options.isHTTP()) {
BF.status(options.isQuiet(), "Identifying " + idName);
imageReader = LociPrefs.makeImageReader();
baseReader = imageReader.getReader(options.isUsingPatternIds() ? new FilePattern(options.getId()).getFiles()[0] : options.getId());
} else if (options.isOMERO()) {
BF.status(options.isQuiet(), "Establishing server connection");
try {
ReflectedUniverse r = new ReflectedUniverse();
r.exec("import loci.ome.io.OmeroReader");
r.exec("baseReader = new OmeroReader()");
ClassList<IFormatReader> classes = new ClassList<IFormatReader>(IFormatReader.class);
r.setVar("classes", classes);
r.exec("class = baseReader.getClass()");
r.exec("classes.addClass(class)");
imageReader = new ImageReader(classes);
baseReader = imageReader.getReader(options.getId());
} catch (Exception exc) {
WindowTools.reportException(exc, options.isQuiet(), "Sorry, there was a problem communicating with the server.");
cancel();
return;
}
} else {
WindowTools.reportException(null, options.isQuiet(), "Sorry, there has been an internal error: unknown data source");
cancel();
return;
}
// attach OME-XML metadata store
Exception exc = null;
try {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
meta = service.createOMEXMLMetadata();
omeXML = null;
} catch (DependencyException de) {
exc = de;
} catch (ServiceException se) {
exc = se;
}
if (exc != null) {
WindowTools.reportException(exc, options.isQuiet(), "Sorry, there was a problem constructing the OME-XML metadata store");
throw new FormatException(exc);
}
baseReader.setMetadataStore(meta);
BF.status(options.isQuiet(), "");
DebugTools.enableIJLogging(IJ.debugMode);
}
use of loci.formats.services.OMEXMLService in project bioformats by openmicroscopy.
the class OMEXMLReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
in = new RandomAccessInputStream(id);
in.setEncoding("ASCII");
binData = new ArrayList<BinData>();
binDataOffsets = new ArrayList<Long>();
compression = new ArrayList<String>();
DefaultHandler handler = new OMEXMLHandler();
try {
RandomAccessInputStream s = new RandomAccessInputStream(id);
XMLTools.parseXML(s, handler);
s.close();
} catch (IOException e) {
throw new FormatException("Malformed OME-XML", e);
}
int lineNumber = 1;
for (BinData bin : binData) {
int line = bin.getRow();
int col = bin.getColumn();
while (lineNumber < line) {
in.readLine();
lineNumber++;
}
binDataOffsets.add(in.getFilePointer() + col - 1);
}
LOGGER.info("Populating metadata");
OMEXMLMetadata omexmlMeta;
OMEXMLService service;
try {
ServiceFactory factory = new ServiceFactory();
service = factory.getInstance(OMEXMLService.class);
omexmlMeta = service.createOMEXMLMetadata(omexml);
} catch (DependencyException de) {
throw new MissingLibraryException(OMEXMLServiceImpl.NO_OME_XML_MSG, de);
} catch (ServiceException se) {
throw new FormatException(se);
}
hasSPW = omexmlMeta.getPlateCount() > 0;
// TODO
// Hashtable originalMetadata = omexmlMeta.getOriginalMetadata();
// if (originalMetadata != null) metadata = originalMetadata;
int numDatasets = omexmlMeta.getImageCount();
int oldSeries = getSeries();
core.clear();
for (int i = 0; i < numDatasets; i++) {
CoreMetadata ms = new CoreMetadata();
core.add(ms);
setSeries(i);
Integer w = omexmlMeta.getPixelsSizeX(i).getValue();
Integer h = omexmlMeta.getPixelsSizeY(i).getValue();
Integer t = omexmlMeta.getPixelsSizeT(i).getValue();
Integer z = omexmlMeta.getPixelsSizeZ(i).getValue();
Integer c = omexmlMeta.getPixelsSizeC(i).getValue();
if (w == null || h == null || t == null || z == null | c == null) {
throw new FormatException("Image dimensions not found");
}
Boolean endian = null;
if (binData.size() > 0) {
endian = false;
if (omexmlMeta.getPixelsBigEndian(i) != null) {
endian = omexmlMeta.getPixelsBigEndian(i).booleanValue();
} else if (omexmlMeta.getPixelsBinDataCount(i) != 0) {
endian = omexmlMeta.getPixelsBinDataBigEndian(i, 0).booleanValue();
}
}
String pixType = omexmlMeta.getPixelsType(i).toString();
ms.dimensionOrder = omexmlMeta.getPixelsDimensionOrder(i).toString();
ms.sizeX = w.intValue();
ms.sizeY = h.intValue();
ms.sizeT = t.intValue();
ms.sizeZ = z.intValue();
ms.sizeC = c.intValue();
ms.imageCount = getSizeZ() * getSizeC() * getSizeT();
ms.littleEndian = endian == null ? false : !endian.booleanValue();
ms.rgb = false;
ms.interleaved = false;
ms.indexed = false;
ms.falseColor = true;
ms.pixelType = FormatTools.pixelTypeFromString(pixType);
ms.orderCertain = true;
if (omexmlMeta.getPixelsSignificantBits(i) != null) {
ms.bitsPerPixel = omexmlMeta.getPixelsSignificantBits(i).getValue();
}
}
setSeries(oldSeries);
// populate assigned metadata store with the
// contents of the internal OME-XML metadata object
MetadataStore store = getMetadataStore();
service.convertMetadata(omexmlMeta, store);
MetadataTools.populatePixels(store, this, false, false);
}
Aggregations