use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.
the class SimpleTiledWriter method initialize.
/**
* Set up the file reader and writer, ensuring that the input file is
* associated with the reader and the output file is associated with the
* writer.
*
* @return true if the reader and writer were successfully set up, or false
* if an error occurred
* @throws DependencyException thrown if failed to create an OMEXMLService
* @throws IOException thrown if unable to setup input or output stream for reader or writer
* @throws FormatException thrown if invalid ID set for reader or writer or invalid tile size set
* @throws ServiceException thrown if unable to create OME-XML meta data
*/
private void initialize() throws DependencyException, FormatException, IOException, ServiceException {
// construct the object that stores OME-XML metadata
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata omexml = service.createOMEXMLMetadata();
// set up the reader and associate it with the input file
reader = new ImageReader();
reader.setMetadataStore(omexml);
reader.setId(inputFile);
/* initialize-tiling-writer-example-start */
// set up the writer and associate it with the output file
writer = new OMETiffWriter();
writer.setMetadataRetrieve(omexml);
writer.setInterleaved(reader.isInterleaved());
// set the tile size height and width for writing
this.tileSizeX = writer.setTileSizeX(tileSizeX);
this.tileSizeY = writer.setTileSizeY(tileSizeY);
writer.setId(outputFile);
/* initialize-tiling-writer-example-end */
}
use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.
the class OBFReader method initFile.
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
currentInflatedFrame.series = -1;
currentInflatedFrame.number = -1;
in = new RandomAccessInputStream(id);
file_version = getFileVersion(in);
long stackPosition = in.readLong();
final int lengthOfDescription = in.readInt();
final String description = in.readString(lengthOfDescription);
metadata.put("Description", description);
if (file_version >= 2) {
final long meta_data_position = in.readLong();
final long current_position = in.getFilePointer();
in.seek(meta_data_position);
for (String key = readString(); key.length() > 0; key = readString()) {
if (key.equals("ome_xml")) {
final String ome_xml = readString();
try {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
if (service.validateOMEXML(ome_xml)) {
ome_meta_data = service.createOMEXMLMetadata(ome_xml);
for (int image = 0; image != ome_meta_data.getImageCount(); ++image) {
if (ome_meta_data.getPixelsBigEndian(image) == null) {
ome_meta_data.setPixelsBigEndian(Boolean.FALSE, image);
}
int channels = ome_meta_data.getChannelCount(image);
for (int channel = 0; channel != channels; ++channel) {
if (ome_meta_data.getChannelSamplesPerPixel(image, channel) == null) {
ome_meta_data.setChannelSamplesPerPixel(new PositiveInteger(1), image, channel);
}
}
}
service.convertMetadata(ome_meta_data, metadataStore);
OMEXMLMetadata reference = service.getOMEMetadata(service.asRetrieve(metadataStore));
for (int image = 0; image != ome_meta_data.getImageCount(); ++image) {
service.addMetadataOnly(reference, image);
}
}
} catch (DependencyException exception) {
throw new MissingLibraryException(OMEXMLServiceImpl.NO_OME_XML_MSG, exception);
} catch (ServiceException exception) {
throw new FormatException(exception);
} catch (Exception e) {
LOGGER.warn("Could not parse OME-XML metadata", e);
}
break;
} else {
addGlobalMeta(key, readString());
}
}
in.seek(current_position);
}
if (stackPosition != 0) {
core.clear();
do {
stackPosition = initStack(stackPosition);
} while (stackPosition != 0);
}
if (ome_meta_data == null) {
MetadataTools.populatePixels(metadataStore, this);
for (int image = 0; image != core.size(); ++image) {
CoreMetadata meta_data = core.get(image);
final String name = meta_data.seriesMetadata.get("Name").toString();
metadataStore.setImageName(name, image);
@SuppressWarnings("unchecked") final List<Double> lengths = (List<Double>) meta_data.seriesMetadata.get("Lengths");
if (lengths.size() > 0) {
double lengthX = Math.abs(lengths.get(0));
if (lengthX < 0.01) {
lengthX *= 1000000;
}
if (lengthX > 0) {
Length physicalSizeX = FormatTools.getPhysicalSizeX(lengthX / meta_data.sizeX, UNITS.MICROMETER);
if (physicalSizeX != null) {
metadataStore.setPixelsPhysicalSizeX(physicalSizeX, image);
}
}
}
if (lengths.size() > 1) {
double lengthY = Math.abs(lengths.get(1));
if (lengthY < 0.01) {
lengthY *= 1000000;
}
if (lengthY > 0) {
Length physicalSizeY = FormatTools.getPhysicalSizeY(lengthY / meta_data.sizeY, UNITS.MICROMETER);
if (physicalSizeY != null) {
metadataStore.setPixelsPhysicalSizeY(physicalSizeY, image);
}
}
}
if (lengths.size() > 2) {
double lengthZ = Math.abs(lengths.get(2));
if (lengthZ < 0.01) {
lengthZ *= 1000000;
}
if (lengthZ > 0) {
Length physicalSizeZ = FormatTools.getPhysicalSizeZ(lengthZ / meta_data.sizeZ, UNITS.MICROMETER);
if (physicalSizeZ != null) {
metadataStore.setPixelsPhysicalSizeZ(physicalSizeZ, image);
}
}
}
}
}
}
use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.
the class OMETiffReader method setupService.
private void setupService() throws FormatException {
try {
ServiceFactory factory = new ServiceFactory();
service = factory.getInstance(OMEXMLService.class);
} catch (DependencyException de) {
throw new MissingLibraryException(OMEXMLServiceImpl.NO_OME_XML_MSG, de);
}
}
use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.
the class MakeTestOmeTiff method createMetadata.
private IMetadata createMetadata(final String name, final CoreMetadata info) throws DependencyException, ServiceException, EnumerationException {
final ServiceFactory serviceFactory = new ServiceFactory();
final OMEXMLService omexmlService = serviceFactory.getInstance(OMEXMLService.class);
final IMetadata meta = omexmlService.createOMEXMLMetadata();
MetadataTools.populateMetadata(meta, 0, name, info);
if (isModulo) {
meta.setXMLAnnotationID("Annotation:Modulo:0", 0);
meta.setXMLAnnotationNamespace("openmicroscopy.org/omero/dimension/modulo", 0);
meta.setXMLAnnotationDescription("For a description of how 6D, 7D, and 8D data is stored using the Modulo extension see https://docs.openmicroscopy.org/latest/ome-model/developers/6d-7d-and-8d-storage.html", 0);
StringBuilder moduloBlock = new StringBuilder();
moduloBlock.append("<Modulo namespace=\"http://www.openmicroscopy.org/Schemas/Additions/2011-09\">");
if (sizeZsub != 1) {
moduloBlock.append("<ModuloAlongZ Type=\"other\" TypeDescription=\"Example Data Over Z-Plane\" Start=\"0\" Step=\"1\" End=\"");
moduloBlock.append(sizeZsub);
moduloBlock.append("\"/>");
}
if (sizeTsub != 1) {
moduloBlock.append("<ModuloAlongT Type=\"other\" TypeDescription=\"Example Data Over Time \" Start=\"0\" Step=\"1\" End=\"");
moduloBlock.append(sizeTsub);
moduloBlock.append("\"/>");
}
if (sizeCsub != 1) {
moduloBlock.append("<ModuloAlongC Type=\"other\" TypeDescription=\"Example Data Over Channel\" Start=\"0\" Step=\"1\" End=\"");
moduloBlock.append(sizeCsub);
moduloBlock.append("\"/>");
}
moduloBlock.append("</Modulo>");
meta.setXMLAnnotationValue(moduloBlock.toString(), 0);
meta.setImageAnnotationRef("Annotation:Modulo:0", 0, 0);
}
return meta;
}
use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.
the class ConversionTest method createMetadata.
private IMetadata createMetadata(String pixelType, int rgbChannels, int seriesCount, boolean littleEndian) throws Exception {
IMetadata metadata;
try {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
metadata = service.createOMEXMLMetadata();
} catch (DependencyException exc) {
throw new FormatException("Could not create OME-XML store.", exc);
} catch (ServiceException exc) {
throw new FormatException("Could not create OME-XML store.", exc);
}
for (int i = 0; i < seriesCount; i++) {
MetadataTools.populateMetadata(metadata, i, "image #" + i, littleEndian, "XYCZT", pixelType, WIDTH, HEIGHT, 1, rgbChannels, 1, rgbChannels);
}
return metadata;
}
Aggregations