Search in sources :

Example 11 with OMETiffWriter

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

the class OrthogonalReader method readOrthogonalPlanes.

private void readOrthogonalPlanes() throws Exception {
    // Setup logger
    ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    if (debug) {
        root.setLevel(Level.DEBUG);
    } else {
        root.setLevel(Level.INFO);
    }
    ImageReader reader = this.initialiseReader(this.input);
    reader.setSeries(0);
    OMETiffWriter writer = this.initialiseWriter(this.output, reader);
    int index;
    // Write XZ planes
    writer.setSeries(0);
    for (int y = 0; y < reader.getSizeY(); y++) {
        ByteBuffer bufferXZ = ByteBuffer.allocate((int) (0.125 * reader.getBitsPerPixel()) * reader.getSizeX() * reader.getSizeZ());
        for (int z = 0; z < reader.getSizeZ(); z++) {
            index = reader.getIndex(z, 0, 0);
            byte[] line = reader.openBytes(index, 0, y, reader.getSizeX(), 1);
            bufferXZ.put(line);
        }
        log.debug("y: {}, {}", y, bufferXZ.array().length);
        writer.saveBytes(y, bufferXZ.array());
    }
    // Write YZ planes
    writer.setSeries(1);
    for (int x = 0; x < reader.getSizeX(); x++) {
        ByteBuffer bufferYZ = ByteBuffer.allocate((int) (0.125 * reader.getBitsPerPixel()) * reader.getSizeY() * reader.getSizeZ());
        for (int z = 0; z < reader.getSizeZ(); z++) {
            index = reader.getIndex(z, 0, 0);
            byte[] line = reader.openBytes(index, x, 0, 1, reader.getSizeY());
            bufferYZ.put(line);
        }
        log.debug("x: {}, {}", x, bufferYZ.array().length);
        writer.saveBytes(x, bufferYZ.array());
    }
    reader.close();
    writer.close();
}
Also used : OMETiffWriter(loci.formats.out.OMETiffWriter) Logger(org.slf4j.Logger) ImageReader(loci.formats.ImageReader) ByteBuffer(java.nio.ByteBuffer)

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