Search in sources :

Example 91 with FormatException

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

the class LociFunctions method openImagePlus.

public void openImagePlus(String path) {
    ImagePlus[] imps = null;
    try {
        ImporterOptions options = new ImporterOptions();
        options.setId(path);
        options.setSeriesOn(series, true);
        imps = BF.openImagePlus(options);
        for (ImagePlus imp : imps) imp.show();
    } catch (IOException exc) {
        IJ.handleException(exc);
    } catch (FormatException exc) {
        IJ.handleException(exc);
    }
}
Also used : ImporterOptions(loci.plugins.in.ImporterOptions) IOException(java.io.IOException) ImagePlus(ij.ImagePlus) FormatException(loci.formats.FormatException)

Example 92 with FormatException

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

the class LociFunctions method openThumbImagePlus.

public void openThumbImagePlus(String path) {
    ImagePlus[] imps = null;
    try {
        ImporterOptions options = new ImporterOptions();
        options.setId(path);
        options.setSeriesOn(series, true);
        imps = BF.openThumbImagePlus(options);
        for (ImagePlus imp : imps) imp.show();
    } catch (IOException exc) {
        IJ.handleException(exc);
    } catch (FormatException exc) {
        IJ.handleException(exc);
    }
}
Also used : ImporterOptions(loci.plugins.in.ImporterOptions) IOException(java.io.IOException) ImagePlus(ij.ImagePlus) FormatException(loci.formats.FormatException)

Example 93 with FormatException

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

the class MetadataConfigurableTest method testSetId.

@Test
public void testSetId() throws FormatException, IOException {
    long t0 = System.currentTimeMillis();
    pixelsOnly.setId(id);
    assertEquals(MetadataLevel.MINIMUM, pixelsOnly.getMetadataOptions().getMetadataLevel());
    long t1 = System.currentTimeMillis();
    all.setId(id);
    assertEquals(MetadataLevel.ALL, all.getMetadataOptions().getMetadataLevel());
    assertFalse(0 == all.getSeriesMetadata().size() + all.getGlobalMetadata().size());
    long t2 = System.currentTimeMillis();
    System.err.println(String.format("Pixels only: %d -- All: %d", t1 - t0, t2 - t1));
    IMetadata metadata = null;
    try {
        ServiceFactory factory = new ServiceFactory();
        OMEXMLService service = factory.getInstance(OMEXMLService.class);
        metadata = service.createOMEXMLMetadata();
        noOverlays.setMetadataStore(metadata);
    } catch (Exception e) {
        throw new FormatException("Cannot initialize OMEXML metadata store");
    }
    noOverlays.setId(id);
    assertEquals(MetadataLevel.NO_OVERLAYS, noOverlays.getMetadataOptions().getMetadataLevel());
    assertEquals(metadata.getROICount(), 0);
}
Also used : IMetadata(loci.formats.meta.IMetadata) ServiceFactory(loci.common.services.ServiceFactory) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException) SkipException(org.testng.SkipException) IOException(java.io.IOException) FormatException(loci.formats.FormatException) Test(org.testng.annotations.Test)

Example 94 with FormatException

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

the class FormatReaderTest method testConsistentReader.

@Test(groups = { "all", "fast", "automated" })
public void testConsistentReader() {
    if (config == null)
        throw new SkipException("No config tree");
    String testName = "testConsistentReader";
    if (!initFile())
        result(testName, false, "initFile");
    String format = config.getReader();
    IFormatReader r = reader;
    if (r instanceof ImageReader) {
        r = ((ImageReader) r).getReader();
    } else if (r instanceof ReaderWrapper) {
        try {
            r = ((ReaderWrapper) r).unwrap();
        } catch (FormatException e) {
        } catch (IOException e) {
        }
    }
    String realFormat = TestTools.shortClassName(r);
    result(testName, realFormat.equals(format), realFormat);
}
Also used : IFormatReader(loci.formats.IFormatReader) SkipException(org.testng.SkipException) IOException(java.io.IOException) ImageReader(loci.formats.ImageReader) BufferedImageReader(loci.formats.gui.BufferedImageReader) ReaderWrapper(loci.formats.ReaderWrapper) FormatException(loci.formats.FormatException) Test(org.testng.annotations.Test)

Example 95 with FormatException

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

the class FileConvert 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
 */
private boolean initialize() {
    Exception exception = null;
    try {
        // 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 ImageWriter();
        writer.setMetadataRetrieve(omexml);
        writer.setInterleaved(reader.isInterleaved());
        writer.setId(outputFile);
    } catch (FormatException e) {
        exception = e;
    } catch (IOException e) {
        exception = e;
    } catch (DependencyException e) {
        exception = e;
    } catch (ServiceException e) {
        exception = e;
    }
    if (exception != null) {
        System.err.println("Failed to initialize files.");
        exception.printStackTrace();
    }
    return exception == null;
}
Also used : IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) ImageWriter(loci.formats.ImageWriter) IOException(java.io.IOException) ImageReader(loci.formats.ImageReader) DependencyException(loci.common.services.DependencyException) FormatException(loci.formats.FormatException) ServiceException(loci.common.services.ServiceException) IOException(java.io.IOException) DependencyException(loci.common.services.DependencyException) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException)

Aggregations

FormatException (loci.formats.FormatException)246 IOException (java.io.IOException)91 CoreMetadata (loci.formats.CoreMetadata)86 RandomAccessInputStream (loci.common.RandomAccessInputStream)73 MetadataStore (loci.formats.meta.MetadataStore)66 Location (loci.common.Location)48 DependencyException (loci.common.services.DependencyException)44 ServiceException (loci.common.services.ServiceException)43 Length (ome.units.quantity.Length)39 ServiceFactory (loci.common.services.ServiceFactory)35 ArrayList (java.util.ArrayList)33 IFD (loci.formats.tiff.IFD)32 TiffParser (loci.formats.tiff.TiffParser)25 OMEXMLService (loci.formats.services.OMEXMLService)23 Time (ome.units.quantity.Time)23 Timestamp (ome.xml.model.primitives.Timestamp)23 ImagePlus (ij.ImagePlus)21 ImageReader (loci.formats.ImageReader)20 IMetadata (loci.formats.meta.IMetadata)18 IFormatReader (loci.formats.IFormatReader)14