Search in sources :

Example 76 with FormatException

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

the class DimensionSwapperTest method createDimSwapper.

@DataProvider(name = "swapper")
public Object[][] createDimSwapper() {
    Location.mapId(TEST_FILE, TEST_FILE);
    DimensionSwapper swapper = new DimensionSwapper();
    try {
        swapper.setId(TEST_FILE);
    } catch (FormatException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    swapper.setOutputOrder(OUTPUT_ORDER);
    return new Object[][] { { swapper } };
}
Also used : DimensionSwapper(loci.formats.DimensionSwapper) IOException(java.io.IOException) FormatException(loci.formats.FormatException) DataProvider(org.testng.annotations.DataProvider)

Example 77 with FormatException

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

the class LosslessJPEG2000Test method setUp.

@BeforeMethod
public void setUp() throws Exception {
    File temp8 = File.createTempFile("test", ".jp2");
    File temp16 = File.createTempFile("test", ".jp2");
    temp8.deleteOnExit();
    temp16.deleteOnExit();
    Location.mapId(FILE_8, temp8.getAbsolutePath());
    Location.mapId(FILE_16, temp16.getAbsolutePath());
    IMetadata metadata8;
    try {
        ServiceFactory factory = new ServiceFactory();
        OMEXMLService service = factory.getInstance(OMEXMLService.class);
        metadata8 = 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);
    }
    MetadataTools.populateMetadata(metadata8, 0, "foo", false, "XYCZT", "uint8", 1, 1, 1, 1, 1, 1);
    IFormatWriter writer8 = new JPEG2000Writer();
    writer8.setMetadataRetrieve(metadata8);
    writer8.setId(FILE_8);
    writer8.saveBytes(0, PIXELS_8);
    writer8.close();
    IMetadata metadata16;
    try {
        ServiceFactory factory = new ServiceFactory();
        OMEXMLService service = factory.getInstance(OMEXMLService.class);
        metadata16 = 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);
    }
    MetadataTools.populateMetadata(metadata16, 0, "foo", false, "XYCZT", "uint16", 1, 1, 1, 1, 1, 1);
    IFormatWriter writer16 = new JPEG2000Writer();
    writer16.setMetadataRetrieve(metadata16);
    writer16.setId(FILE_16);
    writer16.saveBytes(0, PIXELS_16);
    writer16.close();
}
Also used : IFormatWriter(loci.formats.IFormatWriter) JPEG2000Writer(loci.formats.out.JPEG2000Writer) IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) DependencyException(loci.common.services.DependencyException) File(java.io.File) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 78 with FormatException

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

the class ImporterTest method colorizeSubcaseTester.

private void colorizeSubcaseTester(int pixType, int sizeC, int rgb, boolean indexed, boolean falseColor, int lutLen) {
    if ((pixType != FormatTools.UINT8) && (pixType != FormatTools.UINT16))
        throw new IllegalArgumentException("Invalid pixelType: not UINT8 or UINT16 (" + pixType + ")");
    if (sizeC % rgb != 0)
        throw new IllegalArgumentException("Bad combo of sizeC and rgb: " + sizeC + " " + rgb);
    int channelsPerPlane = rgb;
    if (channelsPerPlane > 7)
        throw new IllegalArgumentException("Bad sizeC; channelsPerPlane > 7 : " + channelsPerPlane);
    int sizeX = 60, sizeY = 30, sizeZ = 1, sizeT = 1, numSeries = 1;
    String path = constructFakeFilename("colorColorized", pixType, sizeX, sizeY, sizeZ, sizeC, sizeT, numSeries, indexed, rgb, falseColor, lutLen);
    LOGGER.debug("colorizeSubcaseTester: {}", path);
    ImagePlus[] imps = null;
    try {
        ImporterOptions options = new ImporterOptions();
        options.setAutoscale(false);
        options.setColorMode(ImporterOptions.COLOR_MODE_COLORIZED);
        options.setId(path);
        imps = BF.openImagePlus(options);
    } catch (IOException e) {
        fail(e.getMessage());
    } catch (FormatException e) {
        fail(e.getMessage());
    }
    impsCountTest(imps, 1);
    ImagePlus imp = imps[0];
    if (lutLen == -1)
        lutLen = 3;
    int expectedSizeC = effectiveC(sizeC, rgb, lutLen, indexed, falseColor);
    xyzctTest(imp, sizeX, sizeY, sizeZ, expectedSizeC, sizeT);
    if (imp.isComposite()) {
        CompositeImage ci = (CompositeImage) imp;
        assertTrue(ci.hasCustomLuts());
        assertEquals(CompositeImage.COLOR, ci.getMode());
        // TODO - falseColor stuff needs to be impl
        if (!falseColor)
            colorTests(ci, expectedSizeC, DEFAULT_COLOR_ORDER);
    } else {
        LOGGER.debug("  Not a composite image");
    }
}
Also used : CompositeImage(ij.CompositeImage) IOException(java.io.IOException) ImagePlus(ij.ImagePlus) FormatException(loci.formats.FormatException)

Example 79 with FormatException

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

the class ImporterTest method outputStackOrderTester.

/**
 * tests BF's options.setStackOrder()
 */
private void outputStackOrderTester(boolean virtual, int pixType, ChannelOrder order, int x, int y, int z, int c, int t) {
    String bfChOrder = bfChanOrd(order);
    String chOrder = order.toString();
    String path = constructFakeFilename("stack", pixType, x, y, z, c, t, -1, false, -1, false, -1);
    ImagePlus[] imps = null;
    try {
        ImporterOptions options = new ImporterOptions();
        options.setAutoscale(false);
        options.setVirtual(virtual);
        options.setId(path);
        options.setStackOrder(bfChOrder);
        imps = BF.openImagePlus(options);
    } catch (IOException e) {
        fail(e.getMessage());
    } catch (FormatException e) {
        fail(e.getMessage());
    }
    impsCountTest(imps, 1);
    ImagePlus imp = imps[0];
    xyzctTest(imp, x, y, z, c, t);
    stackTest(imp, z * c * t);
    stackInSpecificOrderTest(imp, chOrder);
}
Also used : IOException(java.io.IOException) ImagePlus(ij.ImagePlus) FormatException(loci.formats.FormatException)

Example 80 with FormatException

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

the class ImporterTest method colorCustomTester.

/**
 * tests BF's options.setColorMode(custom)
 */
private void colorCustomTester(boolean virtual, int pixType, boolean indexed, int channels, int chanPerPlane, boolean falseColor, int numSeries) {
    int sizeX = 55, sizeY = 71, sizeZ = 3, sizeT = 4;
    String path = constructFakeFilename("colorCustom", pixType, sizeX, sizeY, sizeZ, channels, sizeT, numSeries, indexed, chanPerPlane, falseColor, -1);
    LOGGER.debug("colorCustomTester: {}", path);
    ImagePlus[] imps = null;
    try {
        ImporterOptions options = new ImporterOptions();
        options.setAutoscale(false);
        options.setVirtual(virtual);
        options.setColorMode(ImporterOptions.COLOR_MODE_CUSTOM);
        int maxChannels = (channels <= 7) ? channels : 7;
        for (int s = 0; s < numSeries; s++) for (int c = 0; c < maxChannels; c++) options.setCustomColor(s, c, CUSTOM_COLOR_ORDER[c]);
        options.setId(path);
        imps = BF.openImagePlus(options);
    } catch (IOException e) {
        fail(e.getMessage());
    } catch (FormatException e) {
        fail(e.getMessage());
    }
    impsCountTest(imps, 1);
    ImagePlus imp = imps[0];
    int lutLen = 3;
    int expectedSizeC = effectiveC(channels, chanPerPlane, lutLen, indexed, falseColor);
    xyzctTest(imp, sizeX, sizeY, sizeZ, expectedSizeC, sizeT);
    if ((expectedSizeC >= 2) && (expectedSizeC <= 7)) {
        assertTrue(imp.isComposite());
        CompositeImage ci = (CompositeImage) imp;
        assertTrue(ci.hasCustomLuts());
        assertEquals(CompositeImage.COLOR, ci.getMode());
        colorTests(ci, expectedSizeC, CUSTOM_COLOR_ORDER);
    } else // expectedSizeC < 2 or > 7 - we should have gotten back a regular ImagePlus
    {
        assertFalse(imp.isComposite());
        imagePlusLutTest(imp, indexed, falseColor, CUSTOM_COLOR_ORDER[0]);
    }
    stackInCztOrderTest(imp, sizeZ, expectedSizeC, sizeT, indexed, falseColor);
// TODO : i've done no pixel testing
}
Also used : CompositeImage(ij.CompositeImage) IOException(java.io.IOException) ImagePlus(ij.ImagePlus) 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