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);
}
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;
}
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);
}
}
Aggregations