Search in sources :

Example 1 with OMETiffWriter

use of loci.formats.out.OMETiffWriter in project bioformats by openmicroscopy.

the class OMETiffWriterTest method testCompanion.

@Test
public void testCompanion() throws Exception {
    Path wd = Files.createTempDirectory(this.getClass().getName());
    File outFile = wd.resolve("test.ome.tif").toFile();
    File cFile = wd.resolve("test.companion.ome").toFile();
    String companion = cFile.getAbsolutePath();
    DynamicMetadataOptions options = new DynamicMetadataOptions();
    options.set(OMETiffWriter.COMPANION_KEY, companion);
    int planeCount = WriterUtilities.SIZE_Z * WriterUtilities.SIZE_C * WriterUtilities.SIZE_T;
    OMETiffWriter cwriter = new OMETiffWriter();
    cwriter.setMetadataOptions(options);
    cwriter.setMetadataRetrieve(metadata);
    cwriter.setId(outFile.getAbsolutePath());
    cwriter.setSeries(0);
    byte[] img = new byte[WriterUtilities.SIZE_X * WriterUtilities.SIZE_Y];
    for (int i = 0; i < planeCount; i++) {
        cwriter.saveBytes(i, img);
    }
    cwriter.close();
    assertTrue(cFile.exists());
    OMETiffReader reader = new OMETiffReader();
    reader.setId(companion);
    assertEquals(reader.getSizeX(), WriterUtilities.SIZE_X);
    assertEquals(reader.getSizeY(), WriterUtilities.SIZE_Y);
    assertEquals(reader.getSizeZ(), WriterUtilities.SIZE_Z);
    assertEquals(reader.getSizeC(), WriterUtilities.SIZE_C);
    assertEquals(reader.getSizeT(), WriterUtilities.SIZE_T);
    reader.close();
    outFile.deleteOnExit();
    cFile.deleteOnExit();
    wd.toFile().deleteOnExit();
}
Also used : Path(java.nio.file.Path) OMETiffWriter(loci.formats.out.OMETiffWriter) OMETiffReader(loci.formats.in.OMETiffReader) DynamicMetadataOptions(loci.formats.in.DynamicMetadataOptions) File(java.io.File) Test(org.testng.annotations.Test)

Example 2 with OMETiffWriter

use of loci.formats.out.OMETiffWriter 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 3 with OMETiffWriter

use of loci.formats.out.OMETiffWriter 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 4 with OMETiffWriter

use of loci.formats.out.OMETiffWriter 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 5 with OMETiffWriter

use of loci.formats.out.OMETiffWriter in project bioformats by openmicroscopy.

the class OMETiffWriterTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    writer = new OMETiffWriter();
    metadata = WriterUtilities.createMetadata();
    for (int i = 0; i < 1024 * 1024; i++) {
        buf[i] = (byte) (i % 255);
    }
}
Also used : OMETiffWriter(loci.formats.out.OMETiffWriter) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

OMETiffWriter (loci.formats.out.OMETiffWriter)11 ImageReader (loci.formats.ImageReader)6 ServiceFactory (loci.common.services.ServiceFactory)5 IMetadata (loci.formats.meta.IMetadata)5 OMEXMLService (loci.formats.services.OMEXMLService)5 Test (org.testng.annotations.Test)3 File (java.io.File)1 ByteBuffer (java.nio.ByteBuffer)1 Path (java.nio.file.Path)1 DependencyException (loci.common.services.DependencyException)1 ServiceException (loci.common.services.ServiceException)1 FormatException (loci.formats.FormatException)1 DynamicMetadataOptions (loci.formats.in.DynamicMetadataOptions)1 OMETiffReader (loci.formats.in.OMETiffReader)1 TiffReader (loci.formats.in.TiffReader)1 MetadataRetrieve (loci.formats.meta.MetadataRetrieve)1 Length (ome.units.quantity.Length)1 EnumerationException (ome.xml.model.enums.EnumerationException)1 Logger (org.slf4j.Logger)1 BeforeMethod (org.testng.annotations.BeforeMethod)1