Search in sources :

Example 66 with ImageReader

use of loci.formats.ImageReader in project bioformats by openmicroscopy.

the class SubResolutionExample method main.

public static void main(String[] args) throws FormatException, IOException {
    // parse command line arguments
    if (args.length < 1) {
        System.err.println("Usage: java SubResolutionExample imageFile");
        System.exit(1);
    }
    String id = args[0];
    // configure reader
    IFormatReader reader = new ImageReader();
    reader.setFlattenedResolutions(false);
    System.out.println("Initializing file: " + id);
    // parse metadata
    reader.setId(id);
    int seriesCount = reader.getSeriesCount();
    System.out.println("  Series count = " + seriesCount);
    for (int series = 0; series < seriesCount; series++) {
        reader.setSeries(series);
        int resolutionCount = reader.getResolutionCount();
        System.out.println("    Resolution count for series #" + series + " = " + resolutionCount);
        for (int r = 0; r < resolutionCount; r++) {
            reader.setResolution(r);
            System.out.println("      Resolution #" + r + " dimensions = " + reader.getSizeX() + " x " + reader.getSizeY());
        }
    }
    reader.close();
}
Also used : IFormatReader(loci.formats.IFormatReader) ImageReader(loci.formats.ImageReader)

Example 67 with ImageReader

use of loci.formats.ImageReader in project bioformats by openmicroscopy.

the class TiledExportExample method main.

public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        System.out.println("Usage: java TiledExportExample <infile> <outfile>");
        System.exit(1);
    }
    ImageReader reader = new ImageReader();
    ImageWriter writer = new ImageWriter();
    IMetadata meta;
    try {
        ServiceFactory factory = new ServiceFactory();
        OMEXMLService service = factory.getInstance(OMEXMLService.class);
        meta = service.createOMEXMLMetadata();
    } catch (DependencyException exc) {
        throw new FormatException("Could not create OME-XML store.", exc);
    } catch (ServiceException exc) {
        throw new FormatException("Could not create OME-XML store.", exc);
    }
    reader.setMetadataStore(meta);
    reader.setId(args[0]);
    writer.setMetadataRetrieve(meta);
    writer.setId(args[1]);
    for (int series = 0; series < reader.getSeriesCount(); series++) {
        reader.setSeries(series);
        writer.setSeries(series);
        for (int image = 0; image < reader.getImageCount(); image++) {
            for (int row = 0; row < 2; row++) {
                for (int col = 0; col < 2; col++) {
                    int w = reader.getSizeX() / 2;
                    int h = reader.getSizeY() / 2;
                    int x = col * w;
                    int y = row * h;
                    /* debug */
                    System.out.println("[" + x + ", " + y + ", " + w + ", " + h + "]");
                    byte[] buf = reader.openBytes(image, x, y, w, h);
                    writer.saveBytes(image, buf, x, y, w, h);
                }
            }
        }
    }
    reader.close();
    writer.close();
}
Also used : IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) ImageWriter(loci.formats.ImageWriter) ImageReader(loci.formats.ImageReader) DependencyException(loci.common.services.DependencyException) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException)

Example 68 with ImageReader

use of loci.formats.ImageReader 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)

Example 69 with ImageReader

use of loci.formats.ImageReader in project bioformats by openmicroscopy.

the class OrthogonalReader method initialiseReader.

private ImageReader initialiseReader(String fileName) throws Exception {
    ImageReader reader = new ImageReader();
    reader.setId(fileName);
    return reader;
}
Also used : ImageReader(loci.formats.ImageReader)

Example 70 with ImageReader

use of loci.formats.ImageReader in project bioformats by openmicroscopy.

the class ReadPhysicalSize method readPhysicalSize.

/**
 * Reads the physical dimensions of the input file provided then converts and displays them in micrometers
 *
 * @param inputFile the file to be read
 * @throws FormatException if a parsing error occurs processing the file.
 * @throws IOException if an I/O error occurs processing the file
 */
public static void readPhysicalSize(final String inputFile) throws FormatException, IOException {
    final ImageReader reader = new ImageReader();
    final IMetadata omeMeta = MetadataTools.createOMEXMLMetadata();
    reader.setMetadataStore(omeMeta);
    reader.setId(inputFile);
    final Unit<Length> targetUnit = UNITS.MICROMETER;
    for (int image = 0; image < omeMeta.getImageCount(); image++) {
        final Length physSizeX = omeMeta.getPixelsPhysicalSizeX(image);
        final Length physSizeY = omeMeta.getPixelsPhysicalSizeY(image);
        final Length physSizeZ = omeMeta.getPixelsPhysicalSizeZ(image);
        System.out.println("Physical calibration - Image: " + image);
        if (physSizeX != null) {
            final Length convertedSizeX = new Length(physSizeX.value(targetUnit), targetUnit);
            System.out.println("\tX = " + physSizeX.value() + " " + physSizeX.unit().getSymbol() + " = " + convertedSizeX.value() + " " + convertedSizeX.unit().getSymbol());
        }
        if (physSizeY != null) {
            final Length convertedSizeY = new Length(physSizeY.value(targetUnit), targetUnit);
            System.out.println("\tY = " + physSizeY.value() + " " + physSizeY.unit().getSymbol() + " = " + convertedSizeY.value() + " " + convertedSizeY.unit().getSymbol());
        }
        if (physSizeZ != null) {
            final Length convertedSizeZ = new Length(physSizeZ.value(targetUnit), targetUnit);
            System.out.println("\tZ = " + physSizeZ.value() + " " + physSizeZ.unit().getSymbol() + " = " + convertedSizeZ.value() + " " + convertedSizeZ.unit().getSymbol());
        }
    }
    reader.close();
}
Also used : IMetadata(loci.formats.meta.IMetadata) Length(ome.units.quantity.Length) ImageReader(loci.formats.ImageReader)

Aggregations

ImageReader (loci.formats.ImageReader)71 ServiceFactory (loci.common.services.ServiceFactory)23 OMEXMLService (loci.formats.services.OMEXMLService)23 FormatException (loci.formats.FormatException)20 IFormatReader (loci.formats.IFormatReader)20 IMetadata (loci.formats.meta.IMetadata)19 Test (org.testng.annotations.Test)15 IOException (java.io.IOException)11 ChannelFiller (loci.formats.ChannelFiller)11 DependencyException (loci.common.services.DependencyException)10 ServiceException (loci.common.services.ServiceException)10 ChannelSeparator (loci.formats.ChannelSeparator)10 MinMaxCalculator (loci.formats.MinMaxCalculator)10 BufferedImageReader (loci.formats.gui.BufferedImageReader)8 ImageWriter (loci.formats.ImageWriter)7 File (java.io.File)6 FileStitcher (loci.formats.FileStitcher)6 OMETiffWriter (loci.formats.out.OMETiffWriter)6 Location (loci.common.Location)5 DimensionSwapper (loci.formats.DimensionSwapper)5