use of org.locationtech.jts.algorithm.MinimumDiameter in project qupath by qupath.
the class ObjectMeasurements method addShapeMeasurements.
private static void addShapeMeasurements(MeasurementList ml, Geometry geom, String baseName, String units, Collection<ShapeFeatures> features) {
boolean isArea = geom instanceof Polygonal;
boolean isLine = geom instanceof Lineal;
var units2 = units + "^2";
if (!baseName.isEmpty() && !baseName.endsWith(" "))
baseName += " ";
double area = geom.getArea();
double length = geom.getLength();
if (isArea && features.contains(ShapeFeatures.AREA))
ml.putMeasurement(baseName + "Area " + units2, area);
if ((isArea || isLine) && features.contains(ShapeFeatures.LENGTH))
ml.putMeasurement(baseName + "Length " + units, length);
if (isArea && features.contains(ShapeFeatures.CIRCULARITY)) {
if (geom instanceof Polygon) {
var polygon = (Polygon) geom;
double ringArea, ringLength;
if (polygon.getNumInteriorRing() == 0) {
ringArea = area;
ringLength = length;
} else {
var ring = ((Polygon) geom).getExteriorRing().getCoordinateSequence();
ringArea = Area.ofRing(ring);
ringLength = Length.ofLine(ring);
}
double circularity = Math.PI * 4 * ringArea / (ringLength * ringLength);
ml.putMeasurement(baseName + "Circularity", circularity);
} else {
logger.debug("Cannot compute circularity for {}", geom.getClass());
}
}
if (isArea && features.contains(ShapeFeatures.SOLIDITY)) {
double solidity = area / geom.convexHull().getArea();
ml.putMeasurement(baseName + "Solidity", solidity);
}
if (features.contains(ShapeFeatures.MAX_DIAMETER)) {
double minCircleRadius = new MinimumBoundingCircle(geom).getRadius();
ml.putMeasurement(baseName + "Max diameter " + units, minCircleRadius * 2);
}
if (features.contains(ShapeFeatures.MIN_DIAMETER)) {
double minDiameter = new MinimumDiameter(geom).getLength();
ml.putMeasurement(baseName + "Min diameter " + units, minDiameter);
}
}
Aggregations