Search in sources :

Example 36 with IFormatReader

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

the class FormatReaderTest method testUnflattenedPixelsHashes.

@Test(groups = { "all", "pixels", "automated" })
public void testUnflattenedPixelsHashes() {
    if (config == null)
        throw new SkipException("No config tree");
    String testName = "testUnflattenedPixelsHashes";
    if (!initFile())
        result(testName, false, "initFile");
    boolean success = true;
    String msg = null;
    try {
        IFormatReader resolutionReader = new BufferedImageReader(new FileStitcher());
        resolutionReader.setFlattenedResolutions(false);
        resolutionReader.setNormalized(true);
        resolutionReader.setOriginalMetadataPopulated(false);
        resolutionReader.setMetadataFiltered(true);
        resolutionReader.setId(id);
        // check the MD5 of the first plane in each resolution
        for (int i = 0; i < resolutionReader.getSeriesCount() && success; i++) {
            resolutionReader.setSeries(i);
            for (int r = 0; r < resolutionReader.getResolutionCount() && success; r++) {
                resolutionReader.setResolution(r);
                config.setSeries(resolutionReader.getCoreIndex());
                long planeSize = -1;
                try {
                    planeSize = DataTools.safeMultiply32(resolutionReader.getSizeX(), resolutionReader.getSizeY(), resolutionReader.getRGBChannelCount(), FormatTools.getBytesPerPixel(resolutionReader.getPixelType()));
                } catch (IllegalArgumentException e) {
                    continue;
                }
                if (planeSize < 0 || !TestTools.canFitInMemory(planeSize)) {
                    continue;
                }
                String md5 = TestTools.md5(resolutionReader.openBytes(0));
                String expected1 = config.getMD5();
                String expected2 = config.getAlternateMD5();
                if (expected1 == null && expected2 == null) {
                    continue;
                }
                if (!md5.equals(expected1) && !md5.equals(expected2)) {
                    success = false;
                    msg = "series " + i + ", resolution " + r;
                }
            }
        }
        resolutionReader.close();
    } catch (Throwable t) {
        if (TestTools.isOutOfMemory(t)) {
            result(testName, true, "Image too large");
            return;
        }
        LOGGER.info("", t);
        success = false;
    }
    result(testName, success, msg);
}
Also used : IFormatReader(loci.formats.IFormatReader) FileStitcher(loci.formats.FileStitcher) SkipException(org.testng.SkipException) BufferedImageReader(loci.formats.gui.BufferedImageReader) Test(org.testng.annotations.Test)

Example 37 with IFormatReader

use of loci.formats.IFormatReader 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 38 with IFormatReader

use of loci.formats.IFormatReader in project TrakEM2 by trakem2.

the class Loader method getDimensions.

/**
 * Read out the width,height of an image using LOCI BioFormats.
 */
public static Dimension getDimensions(final String path) {
    IFormatReader fr = null;
    try {
        fr = new ChannelSeparator();
        fr.setGroupFiles(false);
        fr.setId(path);
        return new Dimension(fr.getSizeX(), fr.getSizeY());
    } catch (final FormatException fe) {
        Utils.log("Error in reading image file at " + path + "\n" + fe);
    } catch (final Exception e) {
        IJError.print(e);
    } finally {
        if (null != fr)
            try {
                fr.close();
            } catch (final IOException ioe) {
                Utils.log2("Could not close IFormatReader: " + ioe);
            }
    }
    return null;
}
Also used : IFormatReader(loci.formats.IFormatReader) Dimension(java.awt.Dimension) IOException(java.io.IOException) ChannelSeparator(loci.formats.ChannelSeparator) FormatException(loci.formats.FormatException) IOException(java.io.IOException) FormatException(loci.formats.FormatException)

Aggregations

IFormatReader (loci.formats.IFormatReader)38 ImageReader (loci.formats.ImageReader)20 FormatException (loci.formats.FormatException)15 IOException (java.io.IOException)10 FileStitcher (loci.formats.FileStitcher)10 Test (org.testng.annotations.Test)8 Location (loci.common.Location)6 ChannelSeparator (loci.formats.ChannelSeparator)6 ServiceException (loci.common.services.ServiceException)5 ServiceFactory (loci.common.services.ServiceFactory)5 ReaderWrapper (loci.formats.ReaderWrapper)5 IMetadata (loci.formats.meta.IMetadata)5 RandomAccessInputStream (loci.common.RandomAccessInputStream)4 ChannelFiller (loci.formats.ChannelFiller)4 CoreMetadata (loci.formats.CoreMetadata)4 DimensionSwapper (loci.formats.DimensionSwapper)4 MinMaxCalculator (loci.formats.MinMaxCalculator)4 BufferedImageReader (loci.formats.gui.BufferedImageReader)4 OMEXMLService (loci.formats.services.OMEXMLService)4 DependencyException (loci.common.services.DependencyException)3