Search in sources :

Example 11 with CompositeImage

use of ij.CompositeImage in project bioformats by openmicroscopy.

the class AutoscaleTest method setup.

/**
 * Reads the image and performs some initial tests.
 */
private ImagePlus setup(int pixelType, boolean autoscale, boolean crop, double calib, int sizeC) {
    final String pix = FormatTools.getPixelTypeString(pixelType);
    final String id = "autoscale&pixelType=" + pix + "&sizeX=" + WIDTH + "&sizeY=" + HEIGHT + "&sizeC=" + sizeC + ".fake";
    ImagePlus[] imps = null;
    try {
        final ImporterOptions options = new ImporterOptions();
        options.setId(id);
        options.setAutoscale(autoscale);
        options.setCrop(crop);
        if (crop)
            options.setCropRegion(0, CROP_REGION);
        imps = BF.openImagePlus(options);
    } catch (FormatException exc) {
        fail(exc.getMessage());
        LOGGER.debug("", exc);
    } catch (IOException exc) {
        fail(exc.getMessage());
        LOGGER.debug("", exc);
    }
    assertTrue(imps != null && imps.length == 1);
    final ImagePlus imp = imps[0];
    assertEquals(sizeC > 1, imp instanceof CompositeImage);
    // check calibration function
    final Calibration cal = imp.getCalibration();
    final int calFunction = cal.getFunction();
    if (calib == 0) {
        assertFalse(calFunction == Calibration.STRAIGHT_LINE);
    } else {
        assertTrue(calFunction == Calibration.STRAIGHT_LINE);
        double[] coeffs = cal.getCoefficients();
        assertTrue(coeffs.length >= 1);
        assertEquals(calib, coeffs[0], 0.0);
    }
    dump(pix, sizeC, autoscale, crop, imp);
    return imp;
}
Also used : CompositeImage(ij.CompositeImage) IOException(java.io.IOException) Calibration(ij.measure.Calibration) ImagePlus(ij.ImagePlus) FormatException(loci.formats.FormatException)

Example 12 with CompositeImage

use of ij.CompositeImage in project bioformats by openmicroscopy.

the class ImporterTest method compositeSubcaseTester.

/**
 * tests BF's options.setColormode(composite) - alternate, later definition
 */
private void compositeSubcaseTester(int sizeC, boolean indexed) {
    int pixType = FormatTools.UINT8, sizeX = 60, sizeY = 30, sizeZ = 2, sizeT = 3, numSeries = 1, rgb = -1, lutLen = -1;
    boolean falseColor = false;
    String path = constructFakeFilename("colorComposite", pixType, sizeX, sizeY, sizeZ, sizeC, sizeT, numSeries, indexed, rgb, falseColor, lutLen);
    ImagePlus[] imps = null;
    try {
        ImporterOptions options = new ImporterOptions();
        options.setAutoscale(false);
        options.setColorMode(ImporterOptions.COLOR_MODE_COMPOSITE);
        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];
    xyzctTest(imp, sizeX, sizeY, sizeZ, sizeC, sizeT);
    assertTrue(imp.isComposite());
    CompositeImage ci = (CompositeImage) imp;
    assertTrue(ci.hasCustomLuts());
    assertEquals(CompositeImage.COMPOSITE, ci.getMode());
    colorTests(ci, sizeC, DEFAULT_COLOR_ORDER);
    stackInZctOrderTest(imp, sizeZ, sizeC, sizeT, indexed, falseColor);
    pixelsTest(imp, pixType, indexed, falseColor);
}
Also used : CompositeImage(ij.CompositeImage) IOException(java.io.IOException) ImagePlus(ij.ImagePlus) FormatException(loci.formats.FormatException)

Example 13 with CompositeImage

use of ij.CompositeImage in project bioformats by openmicroscopy.

the class ImporterTest method colorCompositeTester.

/**
 * tests BF's options.setColorMode(composite)
 */
private void colorCompositeTester(boolean virtual, int pixType, boolean indexed, int channels, int chanPerPlane, boolean falseColor, int numSeries) {
    int sizeX = 55, sizeY = 71, sizeZ = 3, sizeT = 4;
    // reportedly works in BF as long as numSeries*sizeC*3 <= 25
    String path = constructFakeFilename("colorComposite", pixType, sizeX, sizeY, sizeZ, channels, sizeT, numSeries, indexed, chanPerPlane, falseColor, -1);
    LOGGER.debug("colorCompositeTester: {}", path);
    ImagePlus[] imps = null;
    try {
        ImporterOptions options = new ImporterOptions();
        options.setAutoscale(false);
        options.setVirtual(virtual);
        options.setColorMode(ImporterOptions.COLOR_MODE_COMPOSITE);
        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.COMPOSITE, 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 14 with CompositeImage

use of ij.CompositeImage in project bioformats by openmicroscopy.

the class ImporterTest method getColorTable.

// note - the following code relies on setZctPosition() being called previously. Otherwise regular ImagePlus case
// won't work. In general this method not designed for general use but actually just for use by getPixelValue().
/**
 * gets the color table from any kind of ImagePlus (composite or not) - not for general use
 */
private LUT getColorTable(ImagePlus imp, int channel) {
    if (imp instanceof CompositeImage)
        return ((CompositeImage) imp).getChannelLut(channel + 1);
    // else a regular ImagePlus
    IndexColorModel icm = (IndexColorModel) imp.getProcessor().getColorModel();
    // TODO - maybe I can cast from IndexColorModel to LUT here - depends what IJ did.
    // otherwise make a LUT
    byte[] reds = new byte[256], greens = new byte[256], blues = new byte[256];
    icm.getReds(reds);
    icm.getGreens(greens);
    icm.getBlues(blues);
    return new LUT(reds, greens, blues);
}
Also used : CompositeImage(ij.CompositeImage) LUT(ij.process.LUT) IndexColorModel(java.awt.image.IndexColorModel)

Example 15 with CompositeImage

use of ij.CompositeImage in project bioformats by openmicroscopy.

the class ImporterTest method colorDefaultTester.

/**
 * tests BF's options.setColorMode(composite)
 */
private void colorDefaultTester(boolean virtual, int pixType, boolean indexed, int channels, int chanPerPlane, boolean falseColor, int numSeries, boolean wantLutDefined) {
    int sizeX = 55, sizeY = 71, sizeZ = 3, sizeT = 4;
    // reportedly works in BF as long as numSeries*sizeC*3 <= 25
    String path = constructFakeFilename("colorDefault", pixType, sizeX, sizeY, sizeZ, channels, sizeT, numSeries, indexed, chanPerPlane, falseColor, -1);
    LOGGER.debug("colorDefaultTester: {}", path);
    ImagePlus[] imps = null;
    try {
        ImporterOptions options = new ImporterOptions();
        options.setAutoscale(false);
        options.setVirtual(virtual);
        options.setColorMode(ImporterOptions.COLOR_MODE_DEFAULT);
        if (indexed && wantLutDefined) {
            for (int s = 0; s < numSeries; s++) // set the first channel lut to pink to force COLOR mode as return
            options.setCustomColor(s, 0, Color.PINK);
        }
        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;
        assertEquals(chanPerPlane > 1, ci.hasCustomLuts());
        Color[] colorOrder;
        int expectedType;
        if (// TODO : apparently need another test here for channelFiller.isFilled() case so 1/1/indexed works
        chanPerPlane > 1) {
            expectedType = CompositeImage.COMPOSITE;
            colorOrder = DEFAULT_COLOR_ORDER;
        } else if (indexed && wantLutDefined) {
            // TODO - left working here. this case doesn't work yet.
            // have to figure how BF calcs hasChannelLut so I can exercise it here
            expectedType = CompositeImage.COLOR;
            colorOrder = new Color[] { Color.PINK, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE };
        } else {
            expectedType = CompositeImage.GRAYSCALE;
            colorOrder = DEFAULT_COLOR_ORDER;
        }
        assertEquals(expectedType, ci.getMode());
        colorTests(ci, expectedSizeC, colorOrder);
    } 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) Color(java.awt.Color) IOException(java.io.IOException) ImagePlus(ij.ImagePlus) FormatException(loci.formats.FormatException)

Aggregations

CompositeImage (ij.CompositeImage)20 ImagePlus (ij.ImagePlus)15 IOException (java.io.IOException)10 FormatException (loci.formats.FormatException)10 LUT (ij.process.LUT)9 ImageStack (ij.ImageStack)5 Calibration (ij.measure.Calibration)4 ImageProcessor (ij.process.ImageProcessor)4 VirtualImagePlus (loci.plugins.util.VirtualImagePlus)3 GenericDialog (ij.gui.GenericDialog)2 ColorProcessor (ij.process.ColorProcessor)2 Window (java.awt.Window)2 IndexColorModel (java.awt.image.IndexColorModel)2 ImageProcessorReader (loci.plugins.util.ImageProcessorReader)2 FileInfo (ij.io.FileInfo)1 ByteProcessor (ij.process.ByteProcessor)1 FloatProcessor (ij.process.FloatProcessor)1 ShortProcessor (ij.process.ShortProcessor)1 Color (java.awt.Color)1 Image (java.awt.Image)1