Search in sources :

Example 26 with IMetadata

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

the class TiffWriterTest method initializeWriter.

/**
 * Initializes the writer.
 * @param output The file where to write the compressed data.
 * @param compression The compression to use.
 * @param bigTiff Pass <code>true</code> to set the <code>bigTiff</code> flag,
 *                <code>false</code> otherwise.
 * @return See above.
 * @throws Exception Thrown if an error occurred.
 */
private TiffWriter initializeWriter(String output, String compression, boolean bigTiff) throws Exception {
    IMetadata newMetadata = service.createOMEXMLMetadata();
    MetadataConverter.convertMetadata(metadata, newMetadata);
    TiffWriter writer = new TiffWriter();
    writer.setMetadataRetrieve(newMetadata);
    writer.setCompression(compression);
    writer.setWriteSequentially(true);
    writer.setInterleaved(false);
    writer.setBigTiff(bigTiff);
    writer.setId(output);
    return writer;
}
Also used : IMetadata(loci.formats.meta.IMetadata) TiffWriter(loci.formats.out.TiffWriter)

Example 27 with IMetadata

use of loci.formats.meta.IMetadata 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 28 with IMetadata

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

the class FileExportSPW method export.

/**
 * Save a single uint16 plane of data.
 */
public void export() {
    int width = 4, height = 4;
    int pixelType = FormatTools.UINT16;
    Exception exception = null;
    IMetadata omexml = initializeMetadata(width, height, pixelType);
    int series = 0;
    int nSeries = rows * cols * fovPerWell;
    // only save data if the file writer was initialized successfully
    boolean initializationSuccess = initializeWriter(omexml);
    if (initializationSuccess) {
        while (series < nSeries) {
            for (int p = 0; p < sizeT; p++) {
                savePlane(width, height, pixelType, p, series);
            }
            series++;
            if (series < nSeries) {
                try {
                    writer.setSeries(series);
                } catch (FormatException e) {
                    System.err.println("Fatal error unable to select correct image in series! " + e.getMessage());
                    break;
                }
            }
        }
    // endwhile
    }
    // endif
    cleanup();
}
Also used : IMetadata(loci.formats.meta.IMetadata) FormatException(loci.formats.FormatException) EnumerationException(ome.xml.model.enums.EnumerationException) ServiceException(loci.common.services.ServiceException) IOException(java.io.IOException) DependencyException(loci.common.services.DependencyException) FormatException(loci.formats.FormatException)

Example 29 with IMetadata

use of loci.formats.meta.IMetadata 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 30 with IMetadata

use of loci.formats.meta.IMetadata 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

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