Search in sources :

Example 6 with ImageStatistics

use of ij.process.ImageStatistics in project bioformats by openmicroscopy.

the class VirtualImagePlus method getStatistics.

@Override
public ImageStatistics getStatistics(int mOptions, int nBins, double histMin, double histMax) {
    if (this.ip instanceof RecordedImageProcessor) {
        RecordedImageProcessor currentProc = (RecordedImageProcessor) this.ip;
        this.ip = currentProc.getChild();
        setProcessor(getTitle(), this.ip);
        ImageStatistics s = super.getStatistics(mOptions, nBins, histMin, histMax);
        this.ip = currentProc;
        return s;
    }
    return super.getStatistics(mOptions, nBins, histMin, histMax);
}
Also used : ImageStatistics(ij.process.ImageStatistics)

Example 7 with ImageStatistics

use of ij.process.ImageStatistics in project GDSC-SMLM by aherbert.

the class GaussianFit method getLimits.

/**
 * Calculate the min/max limits for the image. The max is set at the 99th percentile of the data.
 *
 * @param ip the ip
 * @return The limits
 */
private static double[] getLimits(ImageProcessor ip) {
    final ImageStatistics stats = ImageStatistics.getStatistics(ip, Measurements.MIN_MAX, null);
    final double[] limits = new double[] { stats.min, stats.max };
    // Use histogram to cover x% of the data
    final int[] data = ip.getHistogram();
    if (data == null) {
        return limits;
    }
    // 8/16 bit greyscale image. Set upper limit to the height of the 99% percentile.
    final int limit = (int) (99.0 * ip.getPixelCount() / 100.0);
    int count = 0;
    int index = 0;
    while (index < data.length) {
        count += data[index];
        if (count > limit) {
            break;
        }
        index++;
    }
    limits[1] = index;
    return limits;
}
Also used : ImageStatistics(ij.process.ImageStatistics)

Example 8 with ImageStatistics

use of ij.process.ImageStatistics in project GDSC-SMLM by aherbert.

the class PulseActivationAnalysis method autoAdjust.

/**
 * Auto adjust. Copied from {@link ij.plugin.frame.ContrastAdjuster}.
 *
 * <p>Although the ContrastAdjuster records its actions as 'run("Enhance Contrast",
 * "saturated=0.35");' it actually does something else which makes the image easier to see than
 * the afore mentioned command.
 *
 * @param imp the image
 * @param ip the image
 */
private static void autoAdjust(ImagePlus imp, ImageProcessor ip) {
    final ij.measure.Calibration cal = imp.getCalibration();
    imp.setCalibration(null);
    // get uncalibrated stats
    final ImageStatistics stats = imp.getStatistics();
    imp.setCalibration(cal);
    final int limit = stats.pixelCount / 10;
    final int[] histogram = stats.histogram;
    int autoThreshold = 0;
    if (autoThreshold < 10) {
        autoThreshold = 5000;
    } else {
        autoThreshold /= 2;
    }
    final int threshold = stats.pixelCount / autoThreshold;
    int index = -1;
    boolean found = false;
    int count;
    do {
        index++;
        count = histogram[index];
        if (count > limit) {
            count = 0;
        }
        found = count > threshold;
    } while (!found && index < 255);
    final int hmin = index;
    index = 256;
    do {
        index--;
        count = histogram[index];
        if (count > limit) {
            count = 0;
        }
        found = count > threshold;
    } while (!found && index > 0);
    final int hmax = index;
    if (hmax >= hmin) {
        double min = stats.histMin + hmin * stats.binSize;
        double max = stats.histMin + hmax * stats.binSize;
        if (Double.compare(min, max) == 0) {
            min = stats.min;
            max = stats.max;
        }
        imp.setDisplayRange(min, max);
    } else {
        reset(imp);
    }
}
Also used : ImageStatistics(ij.process.ImageStatistics)

Aggregations

ImageStatistics (ij.process.ImageStatistics)8 ImagePlus (ij.ImagePlus)3 Calibration (ij.measure.Calibration)2 ImageProcessor (ij.process.ImageProcessor)2 StackStatistics (ij.process.StackStatistics)2 Displayable (ini.trakem2.display.Displayable)2 Patch (ini.trakem2.display.Patch)2 Rectangle (java.awt.Rectangle)2 ArrayList (java.util.ArrayList)2 GenericDialog (ij.gui.GenericDialog)1 Roi (ij.gui.Roi)1 ZDisplayable (ini.trakem2.display.ZDisplayable)1 PatchStack (ini.trakem2.imaging.PatchStack)1 EqualizeHistogram (ini.trakem2.imaging.filters.EqualizeHistogram)1 TaskFactory (ini.trakem2.parallel.TaskFactory)1 File (java.io.File)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 Future (java.util.concurrent.Future)1