Search in sources :

Example 81 with FormatException

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

the class ImporterTest method testComboManyOptions.

@Test
public void testComboManyOptions() {
    // note - crop and setTStep both don't work with virtualStacks. No need to test virtual here.
    int pixType = FormatTools.UINT16, sizeX = 106, sizeY = 33, sizeZ = 3, sizeC = 5, sizeT = 7;
    int cropOriginX = 0, cropOriginY = 0, cropSizeX = 55, cropSizeY = 16, start = 1, stepBy = 2;
    // orig is ZCT : this is a deadly swap of all dims
    ChannelOrder swappedOrder = ChannelOrder.CTZ;
    // note - to reuse existing code it is necessary that the crop origin is (0,0)
    String path = constructFakeFilename("superCombo", pixType, sizeX, sizeY, sizeZ, sizeC, sizeT, 1, false, -1, false, -1);
    ImagePlus[] imps = null;
    try {
        ImporterOptions options = new ImporterOptions();
        options.setAutoscale(false);
        options.setId(path);
        options.setSwapDimensions(true);
        options.setInputOrder(0, bfChanOrd(swappedOrder));
        options.setCrop(true);
        options.setCropRegion(0, new Region(cropOriginX, cropOriginY, cropSizeX, cropSizeY));
        options.setTStep(0, stepBy);
        options.setTBegin(0, start);
        options.setSplitFocalPlanes(true);
        imps = BF.openImagePlus(options);
    } catch (IOException e) {
        fail(e.getMessage());
    } catch (FormatException e) {
        fail(e.getMessage());
    }
    // we split on Z but that dim was swapped with T
    impsCountTest(imps, sizeT);
    stackCtzSwappedAndCroppedTest(imps, cropSizeX, cropSizeY, sizeZ, sizeC, sizeT, start, stepBy);
}
Also used : Region(loci.common.Region) IOException(java.io.IOException) ImagePlus(ij.ImagePlus) FormatException(loci.formats.FormatException) Test(org.testng.annotations.Test)

Example 82 with FormatException

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

the class ImporterTest method memorySpecifyRangeTester.

/**
 * tests BF's options.set?Begin(), options.set?End(), and options.set?Step()
 */
private void memorySpecifyRangeTester(int z, int c, int t, int zFrom, int zTo, int zBy, int cFrom, int cTo, int cBy, int tFrom, int tTo, int tBy) {
    int pixType = FormatTools.UINT8, x = 50, y = 5;
    String path = constructFakeFilename("range", pixType, x, y, z, c, t, -1, false, -1, false, -1);
    ImagePlus[] imps = null;
    try {
        ImporterOptions options = new ImporterOptions();
        options.setAutoscale(false);
        options.setId(path);
        // z's
        if (zFrom != 0)
            options.setZBegin(0, zFrom);
        if (zTo != z - 1)
            options.setZEnd(0, zTo);
        if (zBy != 1)
            options.setZStep(0, zBy);
        // c's
        if (cFrom != 0)
            options.setCBegin(0, cFrom);
        if (cTo != c - 1)
            options.setCEnd(0, cTo);
        if (cBy != 1)
            options.setCStep(0, cBy);
        // t's
        if (tFrom != 0)
            options.setTBegin(0, tFrom);
        if (tTo != t - 1)
            options.setTEnd(0, tTo);
        if (tBy != 1)
            options.setTStep(0, tBy);
        imps = BF.openImagePlus(options);
    } catch (IOException e) {
        fail(e.getMessage());
    } catch (FormatException e) {
        fail(e.getMessage());
    }
    // should have the data in one series
    impsCountTest(imps, 1);
    ImagePlus imp = imps[0];
    xyzctTest(imp, x, y, numInSeries(zFrom, zTo, zBy), numInSeries(cFrom, cTo, cBy), numInSeries(tFrom, tTo, tBy));
    // should be in correct order
    seriesInZctOrderTest(imp, false, false, zFrom, zTo, zBy, cFrom, cTo, cBy, tFrom, tTo, tBy);
}
Also used : IOException(java.io.IOException) ImagePlus(ij.ImagePlus) FormatException(loci.formats.FormatException)

Example 83 with FormatException

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

the class ImporterTest method colorGrayscaleTester.

/**
 * tests BF's options.setColorMode(gray)
 */
private void colorGrayscaleTester(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("colorGrayscale", pixType, sizeX, sizeY, sizeZ, channels, sizeT, numSeries, indexed, chanPerPlane, falseColor, -1);
    LOGGER.debug("colorGrayscaleTester: {}", path);
    ImagePlus[] imps = null;
    try {
        ImporterOptions options = new ImporterOptions();
        options.setAutoscale(false);
        options.setVirtual(virtual);
        options.setColorMode(ImporterOptions.COLOR_MODE_GRAYSCALE);
        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;
        assertFalse(ci.hasCustomLuts());
        assertEquals(CompositeImage.GRAYSCALE, ci.getMode());
        colorTests(ci, expectedSizeC, DEFAULT_COLOR_ORDER);
    } else // expectedSizeC < 2 or > 7 - we should have gotten back a regular ImagePlus
    {
        assertFalse(imp.isComposite());
        imagePlusLutTest(imp, indexed, falseColor, DEFAULT_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)

Example 84 with FormatException

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

the class ImporterTest method memoryVirtualStackTester.

/**
 * tests BF's options.setVirtual()
 */
private void memoryVirtualStackTester(boolean desireVirtual) {
    int x = 604, y = 531, z = 7, c = 1, t = 1;
    String path = constructFakeFilename("vstack", FormatTools.UINT16, x, y, z, c, t, -1, false, -1, false, -1);
    // open stack
    ImagePlus[] imps = null;
    try {
        ImporterOptions options = new ImporterOptions();
        options.setAutoscale(false);
        options.setId(path);
        // user specified value here
        options.setVirtual(desireVirtual);
        imps = BF.openImagePlus(options);
    } catch (IOException e) {
        fail(e.getMessage());
    } catch (FormatException e) {
        fail(e.getMessage());
    }
    // test results
    impsCountTest(imps, 1);
    ImagePlus imp = imps[0];
    xyzctTest(imp, x, y, z, c, t);
    assertEquals(desireVirtual, imp.getStack().isVirtual());
}
Also used : IOException(java.io.IOException) ImagePlus(ij.ImagePlus) FormatException(loci.formats.FormatException)

Example 85 with FormatException

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

the class ImporterTest method defaultBehaviorTester.

// ******** specific testers  **********************************
/**
 * tests BioFormats when directly calling BF.openImagePlus(path) (no options set)
 */
private void defaultBehaviorTester(int pixType, int x, int y, int z, int c, int t) {
    String path = constructFakeFilename("default", pixType, x, y, z, c, t, -1, false, -1, false, -1);
    ImagePlus[] imps = null;
    try {
        imps = BF.openImagePlus(path);
    } 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);
}
Also used : 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