Search in sources :

Example 31 with ImageReader

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

the class BaseModelNoBinDataReaderTest method testSetId.

@Test
public void testSetId() throws Exception {
    reader = new MinMaxCalculator(new ChannelSeparator(new ChannelFiller(new ImageReader())));
    metadata = new OMEXMLMetadataImpl();
    reader.setMetadataStore(metadata);
    reader.setId(temporaryFile.getAbsolutePath());
}
Also used : MinMaxCalculator(loci.formats.MinMaxCalculator) ChannelFiller(loci.formats.ChannelFiller) ImageReader(loci.formats.ImageReader) ChannelSeparator(loci.formats.ChannelSeparator) OMEXMLMetadataImpl(loci.formats.ome.OMEXMLMetadataImpl) Test(org.testng.annotations.Test)

Example 32 with ImageReader

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

the class EightBitLosslessJPEG2000Test method testLosslessPixels.

@Test
public void testLosslessPixels() throws Exception {
    int failureCount = 0;
    for (int i = 0; i < files.size(); i++) {
        ImageReader reader = new ImageReader();
        reader.setId(files.get(i));
        byte[] plane = reader.openBytes(0);
        if (plane[0] != pixels[i][0]) {
            LOGGER.debug("FAILED on {}", pixels[i][0]);
            failureCount++;
        }
        reader.close();
    }
    assertEquals(failureCount, 0);
}
Also used : ImageReader(loci.formats.ImageReader) Test(org.testng.annotations.Test)

Example 33 with ImageReader

use of loci.formats.ImageReader in project digilib by robcast.

the class BioFormatsDocuImage method identify.

/*
     * (non-Javadoc)
     * 
     * @see digilib.image.DocuImageImpl#identify(digilib.io.ImageInput)
     */
@Override
public ImageInput identify(ImageInput ii) throws IOException {
    ImageReader reader = new ImageReader();
    try {
        reader.setId(ii.getFile().getAbsolutePath());
    } catch (FormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    int width = reader.getSizeX();
    int height = reader.getSizeY();
    String fmt = reader.getFormat();
    String mt = "";
    if (fmt.equalsIgnoreCase("Tagged Image File Format")) {
        mt = "image/tiff";
    } else if (fmt.equalsIgnoreCase("JPEG")) {
        mt = "image/jpeg";
    }
    logger.debug("BioFormats identify: width=" + width + " height=" + height + " format=" + fmt + " mimetype=" + mt);
    ii.setSize(new ImageSize(width, height));
    ii.setMimetype(mt);
    return ii;
}
Also used : ImageSize(digilib.util.ImageSize) ImageReader(loci.formats.ImageReader) BufferedImageReader(loci.formats.gui.BufferedImageReader) FormatException(loci.formats.FormatException)

Example 34 with ImageReader

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

the class ImageInfo method configureReaderPreInit.

public void configureReaderPreInit() throws FormatException, IOException {
    if (omexml) {
        reader.setOriginalMetadataPopulated(originalMetadata);
        try {
            ServiceFactory factory = new ServiceFactory();
            OMEXMLService service = factory.getInstance(OMEXMLService.class);
            reader.setMetadataStore(service.createOMEXMLMetadata(null, omexmlVersion));
        } catch (DependencyException de) {
            throw new MissingLibraryException(OMEXMLServiceImpl.NO_OME_XML_MSG, de);
        } catch (ServiceException se) {
            throw new FormatException(se);
        }
    }
    // check file format
    if (reader instanceof ImageReader) {
        // determine format
        ImageReader ir = (ImageReader) reader;
        if (new Location(id).exists()) {
            LOGGER.info("Checking file format [{}]", ir.getFormat(id));
        }
    } else {
        // verify format
        LOGGER.info("Checking {} format [{}]", reader.getFormat(), reader.isThisType(id) ? "yes" : "no");
    }
    LOGGER.info("Initializing reader");
    if (stitch) {
        reader = new FileStitcher(reader, true);
        Location f = new Location(id);
        String pat = null;
        if (!f.exists()) {
            ((FileStitcher) reader).setUsingPatternIds(true);
            pat = id;
        } else {
            pat = FilePattern.findPattern(f);
        }
        if (pat != null)
            id = pat;
    }
    if (expand)
        reader = new ChannelFiller(reader);
    if (separate)
        reader = new ChannelSeparator(reader);
    if (merge)
        reader = new ChannelMerger(reader);
    if (cache) {
        if (cachedir != null) {
            reader = new Memoizer(reader, 0, new File(cachedir));
        } else {
            reader = new Memoizer(reader, 0);
        }
    }
    minMaxCalc = null;
    if (minmax || autoscale)
        reader = minMaxCalc = new MinMaxCalculator(reader);
    dimSwapper = null;
    if (swapOrder != null || shuffleOrder != null) {
        reader = dimSwapper = new DimensionSwapper(reader);
    }
    reader = biReader = new BufferedImageReader(reader);
    reader.close();
    reader.setNormalized(normalize);
    reader.setMetadataFiltered(filter);
    reader.setGroupFiles(group);
    options.setMetadataLevel(doMeta ? MetadataLevel.ALL : MetadataLevel.MINIMUM);
    options.setValidate(validate);
    reader.setMetadataOptions(options);
    reader.setFlattenedResolutions(flat);
}
Also used : ServiceFactory(loci.common.services.ServiceFactory) Memoizer(loci.formats.Memoizer) ChannelMerger(loci.formats.ChannelMerger) ChannelFiller(loci.formats.ChannelFiller) BufferedImageReader(loci.formats.gui.BufferedImageReader) DependencyException(loci.common.services.DependencyException) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException) ChannelSeparator(loci.formats.ChannelSeparator) ServiceException(loci.common.services.ServiceException) FileStitcher(loci.formats.FileStitcher) MinMaxCalculator(loci.formats.MinMaxCalculator) MissingLibraryException(loci.formats.MissingLibraryException) DimensionSwapper(loci.formats.DimensionSwapper) ImageReader(loci.formats.ImageReader) BufferedImageReader(loci.formats.gui.BufferedImageReader) File(java.io.File) Location(loci.common.Location)

Example 35 with ImageReader

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

the class ImageInfo method testRead.

/**
 * A utility method for reading a file from the command line,
 * and displaying the results in a simple display.
 */
public boolean testRead(String[] args) throws FormatException, ServiceException, IOException {
    for (final String arg : args) {
        if (HELP_ARGUMENTS.contains(arg)) {
            if (reader == null) {
                reader = new ImageReader();
            }
            printUsage();
            return false;
        }
    }
    boolean validArgs = parseArgs(args);
    if (!validArgs)
        return false;
    if (printVersion) {
        CommandLineTools.printVersion();
        return true;
    }
    CommandLineTools.runUpgradeCheck(args);
    createReader();
    if (id == null) {
        printUsage();
        return false;
    }
    mapLocation();
    configureReaderPreInit();
    // initialize reader
    long s = System.currentTimeMillis();
    try {
        reader.setId(id);
    } catch (FormatException exc) {
        reader.close();
        LOGGER.error("Failure during the reader initialization");
        LOGGER.debug("", exc);
        return false;
    }
    long e = System.currentTimeMillis();
    float sec = (e - s) / 1000f;
    LOGGER.info("Initialization took {}s", sec);
    configureReaderPostInit();
    checkWarnings();
    readCoreMetadata();
    reader.setSeries(series);
    if (flat == false)
        reader.setResolution(resolution);
    initPreMinMaxValues();
    // read pixels
    if (pixels)
        readPixels();
    // read format-specific metadata table
    if (doMeta) {
        printGlobalMetadata();
        printOriginalMetadata();
    }
    // output OME-XML
    if (omexml)
        printOMEXML();
    if (!pixels) {
        reader.close();
    }
    return true;
}
Also used : ImageReader(loci.formats.ImageReader) BufferedImageReader(loci.formats.gui.BufferedImageReader) FormatException(loci.formats.FormatException)

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