Search in sources :

Example 6 with OMETiffWriter

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

the class OMETiffWriterBigTiffLargeImageWidthTest method testImageWidthWrittenCorrectly.

@Test
public void testImageWidthWrittenCorrectly() throws Exception {
    OMETiffWriter writer = new OMETiffWriter();
    writer.setBigTiff(true);
    writer.setMetadataRetrieve(ms);
    writer.setId(target.getAbsolutePath());
    writer.saveBytes(0, buf, 0, 0, buf.length, 1);
    writer.close();
    TiffReader reader = new TiffReader();
    reader.setId(target.getAbsolutePath());
    assertEquals(SIZE_X, reader.getSizeX());
    assertEquals(SIZE_Y, reader.getSizeY());
}
Also used : TiffReader(loci.formats.in.TiffReader) OMETiffWriter(loci.formats.out.OMETiffWriter) Test(org.testng.annotations.Test)

Example 7 with OMETiffWriter

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

the class OMETiffWriterUnicodeTest method testImageWidthWrittenCorrectly.

@Test
public void testImageWidthWrittenCorrectly() throws Exception {
    OMETiffWriter writer = new OMETiffWriter();
    writer.setMetadataRetrieve(ms);
    writer.setId(target.getAbsolutePath());
    writer.saveBytes(0, buf, 0, 0, buf.length, 1);
    writer.close();
    ImageReader reader = new ImageReader();
    reader.setId(target.getAbsolutePath());
    assertEquals(reader.getFormat(), "OME-TIFF");
    reader.close();
}
Also used : OMETiffWriter(loci.formats.out.OMETiffWriter) ImageReader(loci.formats.ImageReader) Test(org.testng.annotations.Test)

Example 8 with OMETiffWriter

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

the class ConvertToOmeTiff method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.out.println("Usage: java ConvertToOmeTiff file1 file2 ...");
        return;
    }
    ImageReader reader = new ImageReader();
    OMETiffWriter writer = new OMETiffWriter();
    for (int i = 0; i < args.length; i++) {
        String id = args[i];
        int dot = id.lastIndexOf(".");
        String outId = (dot >= 0 ? id.substring(0, dot) : id) + ".ome.tif";
        System.out.print("Converting " + id + " to " + outId + " ");
        // record metadata to OME-XML format
        ServiceFactory factory = new ServiceFactory();
        OMEXMLService service = factory.getInstance(OMEXMLService.class);
        IMetadata omexmlMeta = service.createOMEXMLMetadata();
        reader.setMetadataStore(omexmlMeta);
        reader.setId(id);
        // configure OME-TIFF writer
        writer.setMetadataRetrieve(omexmlMeta);
        writer.setId(outId);
        // writer.setCompression("J2K");
        // write out image planes
        int seriesCount = reader.getSeriesCount();
        for (int s = 0; s < seriesCount; s++) {
            reader.setSeries(s);
            writer.setSeries(s);
            int planeCount = reader.getImageCount();
            for (int p = 0; p < planeCount; p++) {
                byte[] plane = reader.openBytes(p);
                // write plane to output file
                writer.saveBytes(p, plane);
                System.out.print(".");
            }
        }
        writer.close();
        reader.close();
        System.out.println(" [done]");
    }
}
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 9 with OMETiffWriter

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

the class MakeTestOmeTiff method createWriter.

private OMETiffWriter createWriter(final String name, final CoreMetadata info, final String id) throws FormatException, IOException {
    final OMETiffWriter out = new OMETiffWriter();
    try {
        out.setMetadataRetrieve(createMetadata(name, info));
    } catch (final DependencyException e) {
        throw new FormatException(e);
    } catch (final ServiceException e) {
        throw new FormatException(e);
    } catch (final EnumerationException e) {
        throw new FormatException(e);
    }
    ensureNonExisting(id);
    out.setId(id);
    return out;
}
Also used : OMETiffWriter(loci.formats.out.OMETiffWriter) ServiceException(loci.common.services.ServiceException) DependencyException(loci.common.services.DependencyException) EnumerationException(ome.xml.model.enums.EnumerationException) FormatException(loci.formats.FormatException)

Example 10 with OMETiffWriter

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

the class TiledReaderWriter 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)

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