use of qupath.lib.analysis.stats.RunningStatistics in project qupath by qupath.
the class DelaunayTriangulation method addClusterMeasurements.
/**
* Compute mean measurements from clustering all connected objects.
*/
public void addClusterMeasurements() {
if (nodeMap == null || nodeMap.isEmpty())
return;
List<Set<PathObject>> clusters = getConnectedClusters();
String key = "Cluster ";
List<String> measurementNames = new ArrayList<>();
for (String s : PathClassifierTools.getAvailableFeatures(nodeMap.keySet())) {
if (!s.startsWith(key))
measurementNames.add(s);
}
RunningStatistics[] averagedMeasurements = new RunningStatistics[measurementNames.size()];
Set<String> missing = new LinkedHashSet<>();
for (Set<PathObject> cluster : clusters) {
for (int i = 0; i < averagedMeasurements.length; i++) averagedMeasurements[i] = new RunningStatistics();
// Arrays.fill(averagedMeasurements, 0);
int n = cluster.size();
for (PathObject pathObject : cluster) {
MeasurementList ml = pathObject.getMeasurementList();
for (int i = 0; i < measurementNames.size(); i++) {
String name = measurementNames.get(i);
double val = ml.getMeasurementValue(name);
if (Double.isFinite(val)) {
averagedMeasurements[i].addValue(val);
} else
missing.add(name);
}
}
for (PathObject pathObject : cluster) {
MeasurementList ml = pathObject.getMeasurementList();
for (int i = 0; i < measurementNames.size(); i++) {
ml.putMeasurement(key + "mean: " + measurementNames.get(i), averagedMeasurements[i].getMean());
}
ml.putMeasurement(key + "size", n);
ml.close();
}
}
if (!missing.isEmpty()) {
logger.warn("Some objects have missing measurements! Statistics will calculated only for objects with measurements available.");
logger.warn("Missing measurements: {}", missing);
// System.err.println("Missing measurements will be ignored! " + nMissing);
}
}
use of qupath.lib.analysis.stats.RunningStatistics in project qupath by qupath.
the class WatershedNucleiCV method computeRunningStatistics.
private RunningStatistics computeRunningStatistics(float[] pxIntensities, byte[] pxMask, int width, Rect bounds) {
RunningStatistics stats = new RunningStatistics();
for (int i = 0; i < pxMask.length; i++) {
if (pxMask[i] == 0)
continue;
// Compute the image index
int x = i % bounds.width() + bounds.x();
int y = i % bounds.width() + bounds.y();
// Add the value
stats.addValue(pxIntensities[y * width + x]);
}
return stats;
}
use of qupath.lib.analysis.stats.RunningStatistics in project qupath by qupath.
the class HaralickFeaturesPlugin method addBasicStatistics.
static void addBasicStatistics(final SimpleImage img, final MeasurementList measurementList, final String name) {
RunningStatistics stats = StatisticsHelper.computeRunningStatistics(img);
measurementList.putMeasurement(name + " Mean", stats.getMean());
measurementList.putMeasurement(name + " Min", stats.getMin());
measurementList.putMeasurement(name + " Max", stats.getMax());
measurementList.putMeasurement(name + " Range", stats.getRange());
measurementList.putMeasurement(name + " Std.dev.", stats.getStdDev());
// Compute skewness and kurtosis
double m = stats.getMean();
double skewness = 0;
double kurtosis = 0;
double variance = 0;
double n = stats.size();
for (int y = 0; y < img.getHeight(); y++) {
for (int x = 0; x < img.getWidth(); x++) {
float val = img.getValue(x, y);
if (Float.isNaN(val))
continue;
double d = val - m;
double d3 = d * d * d;
variance += d * d / n;
skewness += d3 / n;
kurtosis += d3 * d / n;
}
}
// TODO: Reinsert skewness & kurtosis measurements, after checking
// // double sigma = stats.getStdDev();
// // System.out.println("Variance difference: " + variance + ", " + stats.getVariance());
// // measurementList.putMeasurement(name + " Variance (again)", variance);
measurementList.putMeasurement(name + " Skewness", skewness / (variance * Math.sqrt(variance)));
measurementList.putMeasurement(name + " Kurtosis", kurtosis / (variance * variance));
}
use of qupath.lib.analysis.stats.RunningStatistics in project qupath by qupath.
the class CoherenceFeaturePlugin method addBasicStatistics.
static void addBasicStatistics(final SimpleImage img, final MeasurementList measurementList, final String name) {
RunningStatistics stats = StatisticsHelper.computeRunningStatistics(img);
measurementList.putMeasurement(name + " Mean", stats.getMean());
measurementList.putMeasurement(name + " Min", stats.getMin());
measurementList.putMeasurement(name + " Max", stats.getMax());
measurementList.putMeasurement(name + " Range", stats.getRange());
measurementList.putMeasurement(name + " Std.dev.", stats.getStdDev());
// measurementList.putMeasurement(String.format("%s Mean", name), stats.getMean());
// measurementList.putMeasurement(String.format("%s Min", name), stats.getMin());
// measurementList.putMeasurement(String.format("%s Max", name), stats.getMax());
// measurementList.putMeasurement(String.format("%s Range", name), stats.getRange());
// measurementList.putMeasurement(String.format("%s Std.dev.", name), stats.getStdDev());
}
use of qupath.lib.analysis.stats.RunningStatistics in project qupath by qupath.
the class HaralickFeatureComputer method measureHaralick.
/**
* Compute Haralick texture features within a specified bounding box (given by xx, yy, ww, and hh).
* <p>
* A mask can also optionally be applied within the bounding box (or may be null). Only non-zero pixels in the mask are included.
*
* @param ip
* @param bpMask
* @param xx
* @param yy
* @param ww
* @param hh
* @param nBins
* @param minValue
* @param maxValue
* @param d
* @return
*/
private static HaralickFeatures measureHaralick(final SimpleImage ip, final SimpleImage bpMask, final int xx, final int yy, final int ww, final int hh, final int nBins, double minValue, double maxValue, final int d) {
// If we have NaNs, compute data min & max
if (Double.isNaN(minValue) || Double.isNaN(maxValue)) {
RunningStatistics stats = getStatistics(ip);
minValue = stats.getMin();
maxValue = stats.getMax();
}
// Create & update cooccurrance matrices
CoocurranceMatrices matrices = updateCooccurrenceMatrices(null, ip, bpMask, xx, yy, ww, hh, nBins, minValue, maxValue, d);
// Get features
HaralickFeatures features = matrices.getMeanFeatures();
return features;
}
Aggregations