Search in sources :

Example 61 with IMetadata

use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.

the class FileExport method export.

/**
 * Save a single 512x512 uint16 plane of random data.
 */
public void export() {
    int width = 512, height = 512;
    int pixelType = FormatTools.UINT16;
    IMetadata omexml = initializeMetadata(width, height, pixelType);
    // only save a plane if the file writer was initialized successfully
    boolean initializationSuccess = initializeWriter(omexml);
    if (initializationSuccess) {
        savePlane(width, height, pixelType);
    }
    cleanup();
}
Also used : IMetadata(loci.formats.meta.IMetadata)

Example 62 with IMetadata

use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.

the class ReadPhysicalSize method readPhysicalSize.

/**
 * Reads the physical dimensions of the input file provided then converts and displays them in micrometers
 *
 * @param inputFile the file to be read
 * @throws FormatException if a parsing error occurs processing the file.
 * @throws IOException if an I/O error occurs processing the file
 */
public static void readPhysicalSize(final String inputFile) throws FormatException, IOException {
    final ImageReader reader = new ImageReader();
    final IMetadata omeMeta = MetadataTools.createOMEXMLMetadata();
    reader.setMetadataStore(omeMeta);
    reader.setId(inputFile);
    final Unit<Length> targetUnit = UNITS.MICROMETER;
    for (int image = 0; image < omeMeta.getImageCount(); image++) {
        final Length physSizeX = omeMeta.getPixelsPhysicalSizeX(image);
        final Length physSizeY = omeMeta.getPixelsPhysicalSizeY(image);
        final Length physSizeZ = omeMeta.getPixelsPhysicalSizeZ(image);
        System.out.println("Physical calibration - Image: " + image);
        if (physSizeX != null) {
            final Length convertedSizeX = new Length(physSizeX.value(targetUnit), targetUnit);
            System.out.println("\tX = " + physSizeX.value() + " " + physSizeX.unit().getSymbol() + " = " + convertedSizeX.value() + " " + convertedSizeX.unit().getSymbol());
        }
        if (physSizeY != null) {
            final Length convertedSizeY = new Length(physSizeY.value(targetUnit), targetUnit);
            System.out.println("\tY = " + physSizeY.value() + " " + physSizeY.unit().getSymbol() + " = " + convertedSizeY.value() + " " + convertedSizeY.unit().getSymbol());
        }
        if (physSizeZ != null) {
            final Length convertedSizeZ = new Length(physSizeZ.value(targetUnit), targetUnit);
            System.out.println("\tZ = " + physSizeZ.value() + " " + physSizeZ.unit().getSymbol() + " = " + convertedSizeZ.value() + " " + convertedSizeZ.unit().getSymbol());
        }
    }
    reader.close();
}
Also used : IMetadata(loci.formats.meta.IMetadata) Length(ome.units.quantity.Length) ImageReader(loci.formats.ImageReader)

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