Search in sources :

Example 1 with CompositeImage

use of ij.CompositeImage in project bioformats by openmicroscopy.

the class Colorizer method applyDisplayRanges.

// -- Helper methods --
private void applyDisplayRanges(ImagePlus imp, int series) {
    if (imp instanceof VirtualImagePlus) {
        // virtual stacks handle their own display ranges
        return;
    }
    final ImporterOptions options = process.getOptions();
    final ImageProcessorReader reader = process.getReader();
    final int pixelType = reader.getPixelType();
    final boolean autoscale = options.isAutoscale() || // always autoscale float data
    FormatTools.isFloatingPoint(pixelType);
    final int cSize = imp.getNChannels();
    final double[] cMin = new double[cSize];
    final double[] cMax = new double[cSize];
    Arrays.fill(cMin, Double.NaN);
    Arrays.fill(cMax, Double.NaN);
    if (autoscale) {
        // extract display ranges for autoscaling
        final MinMaxCalculator minMaxCalc = process.getMinMaxCalculator();
        final int cBegin = process.getCBegin(series);
        final int cStep = process.getCStep(series);
        for (int c = 0; c < cSize; c++) {
            final int cIndex = cBegin + c * cStep;
            Double cMinVal = null, cMaxVal = null;
            try {
                cMinVal = minMaxCalc.getChannelGlobalMinimum(cIndex);
                cMaxVal = minMaxCalc.getChannelGlobalMaximum(cIndex);
                if (cMinVal == null) {
                    cMinVal = minMaxCalc.getChannelKnownMinimum(cIndex);
                }
                if (cMaxVal == null) {
                    cMaxVal = minMaxCalc.getChannelKnownMaximum(cIndex);
                }
            } catch (FormatException exc) {
            } catch (IOException exc) {
            }
            if (cMinVal != null)
                cMin[c] = cMinVal;
            if (cMaxVal != null)
                cMax[c] = cMaxVal;
        }
    }
    // for calibrated data, the offset from zero
    final double zeroOffset = getZeroOffset(imp);
    // fill in default display ranges as appropriate
    final double min, max;
    if (FormatTools.isFloatingPoint(pixelType)) {
        // no defined min and max values for floating point data
        min = max = Double.NaN;
    } else {
        final int bitDepth = reader.getBitsPerPixel();
        final double halfPow = Math.pow(2, bitDepth - 1);
        final double fullPow = 2 * halfPow;
        final boolean signed = FormatTools.isSigned(pixelType);
        if (signed) {
            // signed data is centered at 0
            min = -halfPow;
            max = halfPow - 1;
        } else {
            // unsigned data begins at 0
            min = 0;
            max = fullPow - 1;
        }
        for (int c = 0; c < cSize; c++) {
            if (Double.isNaN(cMin[c]))
                cMin[c] = min;
            if (Double.isNaN(cMax[c]))
                cMax[c] = max;
        }
    }
    // apply display ranges
    if (imp instanceof CompositeImage) {
        // apply channel display ranges
        final CompositeImage compImage = (CompositeImage) imp;
        for (int c = 0; c < cSize; c++) {
            LUT lut = compImage.getChannelLut(c + 1);
            // NB: Uncalibrate values before assigning to LUT min/max.
            lut.min = cMin[c] - zeroOffset;
            lut.max = cMax[c] - zeroOffset;
        }
    } else {
        // compute global display range from channel display ranges
        double globalMin = Double.POSITIVE_INFINITY;
        double globalMax = Double.NEGATIVE_INFINITY;
        for (int c = 0; c < cSize; c++) {
            if (cMin[c] < globalMin)
                globalMin = cMin[c];
            if (cMax[c] > globalMax)
                globalMax = cMax[c];
        }
        // NB: Uncalibrate values before assigning to display range min/max.
        globalMin -= zeroOffset;
        globalMax -= zeroOffset;
        // apply global display range
        ImageProcessor proc = imp.getProcessor();
        if (proc instanceof ColorProcessor) {
            // NB: Should never occur. ;-)
            final ColorProcessor colorProc = (ColorProcessor) proc;
            colorProc.setMinAndMax(globalMin, globalMax, 3);
        } else {
            ColorModel model = proc.getColorModel();
            proc.setMinAndMax(globalMin, globalMax);
            proc.setColorModel(model);
            imp.setDisplayRange(globalMin, globalMax);
        }
    }
}
Also used : VirtualImagePlus(loci.plugins.util.VirtualImagePlus) ImageProcessorReader(loci.plugins.util.ImageProcessorReader) LUT(ij.process.LUT) IOException(java.io.IOException) FormatException(loci.formats.FormatException) ImageProcessor(ij.process.ImageProcessor) ColorProcessor(ij.process.ColorProcessor) CompositeImage(ij.CompositeImage) IndexColorModel(java.awt.image.IndexColorModel) ColorModel(java.awt.image.ColorModel) MinMaxCalculator(loci.formats.MinMaxCalculator)

Example 2 with CompositeImage

use of ij.CompositeImage 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 3 with CompositeImage

use of ij.CompositeImage 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)

Example 4 with CompositeImage

use of ij.CompositeImage 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 5 with CompositeImage

use of ij.CompositeImage in project GDSC-SMLM by aherbert.

the class PulseActivationAnalysis method displayComposite.

private static void displayComposite(ImageProcessor[] images, String name) {
    // We do not yet know the size
    ImageStack stack = null;
    for (int i = 0; i < images.length; i++) {
        final ImageProcessor ip = images[i];
        if (stack == null) {
            stack = new ImageStack(ip.getWidth(), ip.getHeight());
        }
        ip.setColorModel(null);
        stack.addSlice("C" + (i + 1), ip);
    }
    // Create a composite
    ImagePlus imp = new ImagePlus(name, stack);
    imp.setDimensions(images.length, 1, 1);
    final CompositeImage ci = new CompositeImage(imp, IJ.COMPOSITE);
    autoAdjust(ci, ci.getProcessor());
    imp = WindowManager.getImage(name);
    if (imp != null && imp.isComposite()) {
        ci.setMode(imp.getCompositeMode());
        imp.setImage(ci);
        imp.getWindow().toFront();
    } else {
        ci.show();
        imp = ci;
    }
    if (WindowManager.getWindow("Channels") == null) {
        IJ.run("Channels Tool...");
        final Window w = WindowManager.getWindow("Channels");
        if (w == null) {
            return;
        }
        final Window w2 = imp.getWindow();
        if (w2 == null) {
            return;
        }
        final java.awt.Point p = w2.getLocation();
        p.x += w2.getWidth();
        w.setLocation(p);
    }
}
Also used : Window(java.awt.Window) ImageProcessor(ij.process.ImageProcessor) ImageStack(ij.ImageStack) CompositeImage(ij.CompositeImage) ImagePlus(ij.ImagePlus)

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