Search in sources :

Example 31 with IMetadata

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;
}
Also used : PositiveInteger(ome.xml.model.primitives.PositiveInteger) IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) DependencyException(loci.common.services.DependencyException) EnumerationException(ome.xml.model.enums.EnumerationException) FormatException(loci.formats.FormatException) EnumerationException(ome.xml.model.enums.EnumerationException) ServiceException(loci.common.services.ServiceException) IOException(java.io.IOException) DependencyException(loci.common.services.DependencyException) OMEXMLService(loci.formats.services.OMEXMLService)

Example 32 with IMetadata

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;
}
Also used : OMETiffWriter(loci.formats.out.OMETiffWriter) IMetadata(loci.formats.meta.IMetadata) ServiceFactory(loci.common.services.ServiceFactory) Length(ome.units.quantity.Length) MetadataRetrieve(loci.formats.meta.MetadataRetrieve) OMEXMLService(loci.formats.services.OMEXMLService)

Example 33 with IMetadata

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 */
}
Also used : OMETiffWriter(loci.formats.out.OMETiffWriter) IMetadata(loci.formats.meta.IMetadata) ServiceFactory(loci.common.services.ServiceFactory) ImageReader(loci.formats.ImageReader) OMEXMLService(loci.formats.services.OMEXMLService)

Example 34 with IMetadata

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;
}
Also used : IMetadata(loci.formats.meta.IMetadata) ServiceFactory(loci.common.services.ServiceFactory) OMEXMLService(loci.formats.services.OMEXMLService)

Example 35 with IMetadata

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;
}
Also used : IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) DependencyException(loci.common.services.DependencyException) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException)

Aggregations

IMetadata (loci.formats.meta.IMetadata)62 ServiceFactory (loci.common.services.ServiceFactory)35 OMEXMLService (loci.formats.services.OMEXMLService)35 FormatException (loci.formats.FormatException)19 ImageReader (loci.formats.ImageReader)19 ServiceException (loci.common.services.ServiceException)17 Test (org.testng.annotations.Test)17 DependencyException (loci.common.services.DependencyException)15 SkipException (org.testng.SkipException)15 Length (ome.units.quantity.Length)13 IOException (java.io.IOException)9 ImageWriter (loci.formats.ImageWriter)6 Time (ome.units.quantity.Time)6 PositiveInteger (ome.xml.model.primitives.PositiveInteger)6 File (java.io.File)5 IFormatReader (loci.formats.IFormatReader)5 IFormatWriter (loci.formats.IFormatWriter)5 OMETiffWriter (loci.formats.out.OMETiffWriter)5 TiffWriter (loci.formats.out.TiffWriter)5 EnumerationException (ome.xml.model.enums.EnumerationException)4