Search in sources :

Example 1 with ImageProcessorReader

use of loci.plugins.util.ImageProcessorReader 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 ImageProcessorReader

use of loci.plugins.util.ImageProcessorReader in project bioformats by openmicroscopy.

the class ImagePlusReader method finishTiming.

private void finishTiming() {
    final ImageProcessorReader reader = process.getReader();
    long endTime = System.currentTimeMillis();
    double elapsed = (endTime - startTime) / 1000.0;
    if (reader.getImageCount() == 1) {
        notifyListeners(new StatusEvent("Bio-Formats: " + elapsed + " seconds"));
    } else {
        long average = (endTime - startTime) / reader.getImageCount();
        notifyListeners(new StatusEvent("Bio-Formats: " + elapsed + " seconds (" + average + " ms per plane)"));
    }
}
Also used : ImageProcessorReader(loci.plugins.util.ImageProcessorReader) StatusEvent(loci.common.StatusEvent)

Example 3 with ImageProcessorReader

use of loci.plugins.util.ImageProcessorReader in project bioformats by openmicroscopy.

the class ImagePlusReader method readPlanes.

private ImageStack readPlanes(ImportProcess process, int s, List<LUT> luts, boolean thumbnail) throws FormatException, IOException {
    final ImageProcessorReader reader = process.getReader();
    reader.setSeries(s);
    final int zCount = process.getZCount(s);
    final int cCount = process.getCCount(s);
    final int tCount = process.getTCount(s);
    final IMetadata meta = process.getOMEMetadata();
    // get list of planes to load
    final boolean[] load = getPlanesToLoad(s);
    int current = 0, total = 0;
    for (int j = 0; j < load.length; j++) if (load[j])
        total++;
    final List<ImageProcessor> procs = new ArrayList<ImageProcessor>();
    final List<String> labels = new ArrayList<String>();
    // read applicable image planes
    final Region region = process.getCropRegion(s);
    for (int i = 0; i < load.length; i++) {
        if (!load[i])
            continue;
        // limit message update rate
        updateTiming(s, current, current++, total);
        // get image processor for ith plane
        final ImageProcessor[] p = readProcessors(process, i, region, thumbnail);
        if (p == null || p.length == 0) {
            throw new FormatException("Cannot read plane #" + i);
        }
        // generate a label for ith plane
        String label = constructSliceLabel(i, reader, meta, s, zCount, cCount, tCount);
        for (ImageProcessor ip : p) {
            procs.add(ip);
            labels.add(label);
        }
    }
    return createStack(procs, labels, luts);
}
Also used : ImageProcessor(ij.process.ImageProcessor) IMetadata(loci.formats.meta.IMetadata) ImageProcessorReader(loci.plugins.util.ImageProcessorReader) ArrayList(java.util.ArrayList) Region(loci.common.Region) FormatException(loci.formats.FormatException)

Example 4 with ImageProcessorReader

use of loci.plugins.util.ImageProcessorReader in project bioformats by openmicroscopy.

the class ImagePlusReader method getPlanesToLoad.

private boolean[] getPlanesToLoad(int s) {
    final ImageProcessorReader reader = process.getReader();
    final boolean[] load = new boolean[reader.getImageCount()];
    final int cBegin = process.getCBegin(s);
    final int cEnd = process.getCEnd(s);
    final int cStep = process.getCStep(s);
    final int zBegin = process.getZBegin(s);
    final int zEnd = process.getZEnd(s);
    final int zStep = process.getZStep(s);
    final int tBegin = process.getTBegin(s);
    final int tEnd = process.getTEnd(s);
    final int tStep = process.getTStep(s);
    for (int c = cBegin; c <= cEnd; c += cStep) {
        for (int z = zBegin; z <= zEnd; z += zStep) {
            for (int t = tBegin; t <= tEnd; t += tStep) {
                int index = reader.getIndex(z, c, t);
                load[index] = true;
            }
        }
    }
    return load;
}
Also used : ImageProcessorReader(loci.plugins.util.ImageProcessorReader)

Example 5 with ImageProcessorReader

use of loci.plugins.util.ImageProcessorReader in project bioformats by openmicroscopy.

the class ImagePlusReader method updateTiming.

private void updateTiming(int s, int i, int current, int total) {
    final ImageProcessorReader reader = process.getReader();
    long clock = System.currentTimeMillis();
    if (clock - time >= 100) {
        String sLabel = reader.getSeriesCount() > 1 ? ("series " + (s + 1) + ", ") : "";
        String pLabel = "plane " + (i + 1) + "/" + total;
        notifyListeners(new StatusEvent("Reading " + sLabel + pLabel));
        time = clock;
    }
    notifyListeners(new StatusEvent(current, total, null));
}
Also used : ImageProcessorReader(loci.plugins.util.ImageProcessorReader) StatusEvent(loci.common.StatusEvent)

Aggregations

ImageProcessorReader (loci.plugins.util.ImageProcessorReader)20 FormatException (loci.formats.FormatException)5 ImageProcessor (ij.process.ImageProcessor)4 LUT (ij.process.LUT)4 ImagePlus (ij.ImagePlus)3 GenericDialog (ij.gui.GenericDialog)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 VirtualImagePlus (loci.plugins.util.VirtualImagePlus)3 CompositeImage (ij.CompositeImage)2 ImageStack (ij.ImageStack)2 Color (java.awt.Color)2 ColorModel (java.awt.image.ColorModel)2 StatusEvent (loci.common.StatusEvent)2 ChannelFiller (loci.formats.ChannelFiller)2 ChannelSeparator (loci.formats.ChannelSeparator)2 DimensionSwapper (loci.formats.DimensionSwapper)2 MinMaxCalculator (loci.formats.MinMaxCalculator)2 IMetadata (loci.formats.meta.IMetadata)2 BFVirtualStack (loci.plugins.util.BFVirtualStack)2