Search in sources :

Example 21 with OMEXMLService

use of loci.formats.services.OMEXMLService in project bioformats by openmicroscopy.

the class MetadataConfigurableTest method testSetId.

@Test
public void testSetId() throws FormatException, IOException {
    long t0 = System.currentTimeMillis();
    pixelsOnly.setId(id);
    assertEquals(MetadataLevel.MINIMUM, pixelsOnly.getMetadataOptions().getMetadataLevel());
    long t1 = System.currentTimeMillis();
    all.setId(id);
    assertEquals(MetadataLevel.ALL, all.getMetadataOptions().getMetadataLevel());
    assertFalse(0 == all.getSeriesMetadata().size() + all.getGlobalMetadata().size());
    long t2 = System.currentTimeMillis();
    System.err.println(String.format("Pixels only: %d -- All: %d", t1 - t0, t2 - t1));
    IMetadata metadata = null;
    try {
        ServiceFactory factory = new ServiceFactory();
        OMEXMLService service = factory.getInstance(OMEXMLService.class);
        metadata = service.createOMEXMLMetadata();
        noOverlays.setMetadataStore(metadata);
    } catch (Exception e) {
        throw new FormatException("Cannot initialize OMEXML metadata store");
    }
    noOverlays.setId(id);
    assertEquals(MetadataLevel.NO_OVERLAYS, noOverlays.getMetadataOptions().getMetadataLevel());
    assertEquals(metadata.getROICount(), 0);
}
Also used : IMetadata(loci.formats.meta.IMetadata) ServiceFactory(loci.common.services.ServiceFactory) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException) SkipException(org.testng.SkipException) IOException(java.io.IOException) FormatException(loci.formats.FormatException) Test(org.testng.annotations.Test)

Example 22 with OMEXMLService

use of loci.formats.services.OMEXMLService in project bioformats by openmicroscopy.

the class FileConvert 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
 */
private boolean initialize() {
    Exception exception = null;
    try {
        // 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);
        // set up the writer and associate it with the output file
        writer = new ImageWriter();
        writer.setMetadataRetrieve(omexml);
        writer.setInterleaved(reader.isInterleaved());
        writer.setId(outputFile);
    } catch (FormatException e) {
        exception = e;
    } catch (IOException e) {
        exception = e;
    } catch (DependencyException e) {
        exception = e;
    } catch (ServiceException e) {
        exception = e;
    }
    if (exception != null) {
        System.err.println("Failed to initialize files.");
        exception.printStackTrace();
    }
    return exception == null;
}
Also used : IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) ImageWriter(loci.formats.ImageWriter) IOException(java.io.IOException) ImageReader(loci.formats.ImageReader) DependencyException(loci.common.services.DependencyException) FormatException(loci.formats.FormatException) ServiceException(loci.common.services.ServiceException) IOException(java.io.IOException) DependencyException(loci.common.services.DependencyException) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException)

Example 23 with OMEXMLService

use of loci.formats.services.OMEXMLService in project bioformats by openmicroscopy.

the class FileExportSPW method initializeMetadata.

/**
 * Populate the minimum amount of metadata required to export a Plate.
 *
 * @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);
        OMEXMLMetadata meta = service.createOMEXMLMetadata();
        meta.createRoot();
        int plateIndex = 0;
        // count of images
        int series = 0;
        int well = 0;
        // Create Minimal 2x2 Plate
        meta.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
        meta.setPlateRowNamingConvention(NamingConvention.LETTER, 0);
        meta.setPlateColumnNamingConvention(NamingConvention.NUMBER, 0);
        meta.setPlateRows(new PositiveInteger(rows), 0);
        meta.setPlateColumns(new PositiveInteger(cols), 0);
        meta.setPlateName("First test Plate", 0);
        PositiveInteger pwidth = new PositiveInteger(width);
        PositiveInteger pheight = new PositiveInteger(height);
        char rowChar = 'A';
        for (int row = 0; row < rows; row++) {
            for (int column = 0; column < cols; column++) {
                // set up well
                String wellID = MetadataTools.createLSID("Well:", well);
                meta.setWellID(wellID, plateIndex, well);
                meta.setWellRow(new NonNegativeInteger(row), plateIndex, well);
                meta.setWellColumn(new NonNegativeInteger(column), plateIndex, well);
                for (int fov = 0; fov < fovPerWell; fov++) {
                    // Create Image
                    String imageName = rowChar + ":" + Integer.toString(column + 1) + ":FOV:" + Integer.toString(fov + 1);
                    String imageID = MetadataTools.createLSID("Image", well, fov);
                    meta.setImageID(imageID, series);
                    meta.setImageName(imageName, series);
                    String pixelsID = MetadataTools.createLSID("Pixels", row, well, fov);
                    meta.setPixelsID(pixelsID, series);
                    // specify that the pixel data is stored in big-endian format
                    // change 'TRUE' to 'FALSE' to specify little-endian format
                    meta.setPixelsBinDataBigEndian(Boolean.TRUE, series, 0);
                    // specify that the image is stored in ZCT order
                    meta.setPixelsDimensionOrder(DimensionOrder.XYZCT, series);
                    // specify the pixel type of the image
                    meta.setPixelsType(PixelType.fromString(FormatTools.getPixelTypeString(pixelType)), series);
                    // specify the dimensions of the image
                    meta.setPixelsSizeX(pwidth, series);
                    meta.setPixelsSizeY(pheight, series);
                    meta.setPixelsSizeZ(new PositiveInteger(1), series);
                    meta.setPixelsSizeC(new PositiveInteger(1), series);
                    meta.setPixelsSizeT(new PositiveInteger(sizeT), series);
                    // define each channel and specify the number of samples in the
                    // channel the number of samples is 3 for RGB images and 1 otherwise
                    String channelID = MetadataTools.createLSID("Channel", well, fov);
                    meta.setChannelID(channelID, series, 0);
                    meta.setChannelSamplesPerPixel(new PositiveInteger(1), series, 0);
                    // set sample
                    String wellSampleID = MetadataTools.createLSID("WellSample", well, fov);
                    meta.setWellSampleID(wellSampleID, 0, well, fov);
                    // NB sampleIndex here == series ie the image No
                    meta.setWellSampleIndex(new NonNegativeInteger(series), 0, well, fov);
                    meta.setWellSampleImageRef(imageID, 0, well, fov);
                    // add FLIM ModuloAlongT annotation if required
                    // CoreMetadata modlo = createModuloAnn();
                    // meta.addModuloAlong(meta, modlo, series);
                    series++;
                }
                // end of samples
                well++;
            }
            rowChar++;
        }
        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) ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) 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 24 with OMEXMLService

use of loci.formats.services.OMEXMLService in project bioformats by openmicroscopy.

the class OverlappedTiledWriter 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);
    // 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);
}
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 25 with OMEXMLService

use of loci.formats.services.OMEXMLService in project bioformats by openmicroscopy.

the class writeMapAnnotationsExample method main.

public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        System.out.println("Please specify an output file name.");
        System.exit(1);
    }
    String id = args[0];
    // create blank 512x512 image
    System.out.println("Creating random image...");
    int w = 512, h = 512, c = 1;
    int pixelType = FormatTools.UINT16;
    byte[] img = new byte[w * h * c * FormatTools.getBytesPerPixel(pixelType)];
    // fill with random data
    for (int i = 0; i < img.length; i++) img[i] = (byte) (256 * Math.random());
    // Create MapPair Object and add to List
    List<MapPair> mapList = new ArrayList<MapPair>();
    mapList.add(new MapPair("Example Key", "Example Value"));
    mapList.add(new MapPair("Bio-Formats Version", FormatTools.VERSION));
    // create metadata object with minimum required metadata fields
    System.out.println("Populating metadata...");
    // add (minimum+Map)Annotations to the metadata object
    ServiceFactory factory = new ServiceFactory();
    OMEXMLService service = factory.getInstance(OMEXMLService.class);
    IMetadata metadata = service.createOMEXMLMetadata();
    metadata.createRoot();
    MetadataTools.populateMetadata(metadata, 0, null, false, "XYZCT", FormatTools.getPixelTypeString(pixelType), w, h, 1, c, 1, c);
    int mapAnnotationIndex = 0;
    int annotationRefIndex = 0;
    String mapAnnotationID = MetadataTools.createLSID("MapAnnotation", 0, mapAnnotationIndex);
    metadata.setMapAnnotationID(mapAnnotationID, mapAnnotationIndex);
    metadata.setMapAnnotationValue(mapList, mapAnnotationIndex);
    metadata.setMapAnnotationAnnotator("Example Map Annotation", mapAnnotationIndex);
    metadata.setMapAnnotationDescription("Example Description", mapAnnotationIndex);
    metadata.setMapAnnotationNamespace("Example NameSpace", mapAnnotationIndex);
    metadata.setImageAnnotationRef(mapAnnotationID, 0, annotationRefIndex);
    mapAnnotationIndex = 1;
    annotationRefIndex = 1;
    mapAnnotationID = MetadataTools.createLSID("MapAnnotation", 0, mapAnnotationIndex);
    metadata.setMapAnnotationID(mapAnnotationID, mapAnnotationIndex);
    metadata.setMapAnnotationValue(mapList, mapAnnotationIndex);
    metadata.setMapAnnotationAnnotator("Example Map Annotation 1", mapAnnotationIndex);
    metadata.setMapAnnotationDescription("Example Description 1", mapAnnotationIndex);
    metadata.setMapAnnotationNamespace("Example NameSpace 1", mapAnnotationIndex);
    metadata.setImageAnnotationRef(mapAnnotationID, 0, annotationRefIndex);
    // Initialize writer and save file
    ImageWriter writer = new ImageWriter();
    writer.setMetadataRetrieve(metadata);
    writer.setId(id);
    writer.saveBytes(0, img);
    writer.close();
    System.out.println("Done.");
}
Also used : MapPair(ome.xml.model.MapPair) IMetadata(loci.formats.meta.IMetadata) ServiceFactory(loci.common.services.ServiceFactory) ArrayList(java.util.ArrayList) ImageWriter(loci.formats.ImageWriter) OMEXMLService(loci.formats.services.OMEXMLService)

Aggregations

OMEXMLService (loci.formats.services.OMEXMLService)59 ServiceFactory (loci.common.services.ServiceFactory)57 IMetadata (loci.formats.meta.IMetadata)35 DependencyException (loci.common.services.DependencyException)28 ServiceException (loci.common.services.ServiceException)26 FormatException (loci.formats.FormatException)23 ImageReader (loci.formats.ImageReader)21 PositiveInteger (ome.xml.model.primitives.PositiveInteger)12 IOException (java.io.IOException)11 MetadataStore (loci.formats.meta.MetadataStore)7 File (java.io.File)6 Location (loci.common.Location)6 ImageWriter (loci.formats.ImageWriter)6 OMEXMLMetadata (loci.formats.ome.OMEXMLMetadata)6 Length (ome.units.quantity.Length)6 BeforeClass (org.testng.annotations.BeforeClass)6 IFormatWriter (loci.formats.IFormatWriter)5 MissingLibraryException (loci.formats.MissingLibraryException)5 OMETiffWriter (loci.formats.out.OMETiffWriter)5 ArrayList (java.util.ArrayList)4