use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.
the class FileExport method initializeMetadata.
/**
* Populate the minimum amount of metadata required to export an image.
*
* @param width the width (in pixels) of the image
* @param height the height (in pixels) of the image
* @param pixelType the pixel type of the image; @see loci.formats.FormatTools
*/
private IMetadata initializeMetadata(int width, int height, int pixelType) {
Exception exception = null;
try {
// create the OME-XML metadata storage object
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata meta = service.createOMEXMLMetadata();
meta.createRoot();
// define each stack of images - this defines a single stack of images
meta.setImageID("Image:0", 0);
meta.setPixelsID("Pixels:0", 0);
// specify that the pixel data is stored in big-endian format
// change 'TRUE' to 'FALSE' to specify little-endian format
meta.setPixelsBinDataBigEndian(Boolean.TRUE, 0, 0);
// specify that the images are stored in ZCT order
meta.setPixelsDimensionOrder(DimensionOrder.XYZCT, 0);
// specify that the pixel type of the images
meta.setPixelsType(PixelType.fromString(FormatTools.getPixelTypeString(pixelType)), 0);
// specify the dimensions of the images
meta.setPixelsSizeX(new PositiveInteger(width), 0);
meta.setPixelsSizeY(new PositiveInteger(height), 0);
meta.setPixelsSizeZ(new PositiveInteger(1), 0);
meta.setPixelsSizeC(new PositiveInteger(1), 0);
meta.setPixelsSizeT(new PositiveInteger(1), 0);
// define each channel and specify the number of samples in the channel
// the number of samples is 3 for RGB images and 1 otherwise
meta.setChannelID("Channel:0:0", 0, 0);
meta.setChannelSamplesPerPixel(new PositiveInteger(1), 0, 0);
return meta;
} catch (DependencyException e) {
exception = e;
} catch (ServiceException e) {
exception = e;
} catch (EnumerationException e) {
exception = e;
}
System.err.println("Failed to populate OME-XML metadata object.");
exception.printStackTrace();
return null;
}
use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.
the class OrthogonalReader method initialiseWriter.
private OMETiffWriter initialiseWriter(String fileName, ImageReader reader) throws Exception {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata metadata = service.createOMEXMLMetadata();
MetadataRetrieve mr = (MetadataRetrieve) reader.getMetadataStore();
Length originalSizeX = mr.getPixelsPhysicalSizeX(0);
Length originalSizeY = mr.getPixelsPhysicalSizeY(0);
Length originalSizeZ = mr.getPixelsPhysicalSizeZ(0);
// Original XY planes
// XZ planes
MetadataTools.populateMetadata(metadata, 0, "XZ", reader.isLittleEndian(), reader.getDimensionOrder(), FormatTools.getPixelTypeString(reader.getPixelType()), reader.getSizeX(), reader.getSizeZ(), reader.getSizeY(), 1, 1, 1);
metadata.setPixelsPhysicalSizeX(originalSizeX, 0);
metadata.setPixelsPhysicalSizeY(originalSizeZ, 0);
metadata.setPixelsPhysicalSizeZ(originalSizeY, 0);
// YZ planes
MetadataTools.populateMetadata(metadata, 1, "YZ", reader.isLittleEndian(), reader.getDimensionOrder(), FormatTools.getPixelTypeString(reader.getPixelType()), reader.getSizeY(), reader.getSizeZ(), reader.getSizeX(), 1, 1, 1);
metadata.setPixelsPhysicalSizeX(originalSizeY, 1);
metadata.setPixelsPhysicalSizeY(originalSizeZ, 1);
metadata.setPixelsPhysicalSizeZ(originalSizeX, 1);
OMETiffWriter writer = new OMETiffWriter();
writer.setMetadataRetrieve(metadata);
writer.setId(fileName);
return writer;
}
use of loci.formats.meta.IMetadata 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.formats.meta.IMetadata 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.formats.meta.IMetadata 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