use of qupath.lib.objects.PathObjects in project qupath by qupath.
the class PointIOTest method test2ReadPoints.
@Test
public void test2ReadPoints() {
List<PathObject> pathObjects = null;
List<Double[]> pointsList = new ArrayList<>();
try {
pathObjects = PointIO.readPoints(file);
for (var pathObject : pathObjects) {
Point2 point = pathObject.getROI().getAllPoints().get(0);
pointsList.add(new Double[] { point.getX(), point.getY() });
}
} catch (IOException e) {
fail();
}
// Check that we have the same number of sets as originally
assertTrue(pathObjects.size() == 5);
// Check that all coordinates are the same
assertTrue(map.values().stream().allMatch(p -> {
return Arrays.stream(p).anyMatch(o -> pointsList.stream().anyMatch(m -> Arrays.equals(m, o)));
}));
// Check that classes were correctly assigned (Sets 3 & 5)
assertTrue(pathObjects.stream().filter(p -> isInside(map.get(3), p.getROI().getAllPoints().get(0))).allMatch(q -> q.getPathClass().getName().equals("Other")));
assertTrue(pathObjects.stream().filter(p -> isInside(map.get(5), p.getROI().getAllPoints().get(0))).allMatch(q -> q.getPathClass().getName().equals("Tumor")));
// Check that name were correctly assigned (Sets 4 & 5)
assertTrue(pathObjects.stream().filter(p -> isInside(map.get(4), p.getROI().getAllPoints().get(0))).allMatch(q -> q.getName().equals("foo")));
assertTrue(pathObjects.stream().filter(p -> isInside(map.get(5), p.getROI().getAllPoints().get(0))).allMatch(q -> q.getName().equals("bar")));
// Check C, Z and T
assertTrue(pathObjects.stream().allMatch(q -> {
if (isInside(map.get(2), q.getROI().getAllPoints().get(0)))
return (q.getROI().getC() == 2 && q.getROI().getZ() == 1 && q.getROI().getT() == 7);
else
return (q.getROI().getC() == -1 && q.getROI().getZ() == 0 && q.getROI().getT() == 0);
}));
file.delete();
}
use of qupath.lib.objects.PathObjects in project qupath by qupath.
the class Commands method promptToSimplifySelectedAnnotations.
/**
* Show a prompt to selected annotations in a hierarchy.
* @param imageData the current image data
* @param altitudeThreshold default altitude value for simplification
*/
public static void promptToSimplifySelectedAnnotations(ImageData<?> imageData, double altitudeThreshold) {
PathObjectHierarchy hierarchy = imageData.getHierarchy();
List<PathObject> pathObjects = hierarchy.getSelectionModel().getSelectedObjects().stream().filter(p -> p.isAnnotation() && p.hasROI() && p.isEditable() && !p.getROI().isPoint()).collect(Collectors.toList());
if (pathObjects.isEmpty()) {
Dialogs.showErrorMessage("Simplify annotations", "No unlocked shape annotations selected!");
return;
}
String input = Dialogs.showInputDialog("Simplify shape", "Set altitude threshold in pixels.\nHigher values give simpler shapes.", Double.toString(altitudeThreshold));
if (input == null || !(input instanceof String) || ((String) input).trim().length() == 0)
return;
try {
altitudeThreshold = Double.parseDouble(((String) input).trim());
} catch (NumberFormatException e) {
logger.error("Could not parse altitude threshold from {}", input);
return;
}
if (altitudeThreshold <= 0) {
Dialogs.showErrorMessage("Simplify shape", "Amplitude threshold should be greater than zero!");
return;
}
long startTime = System.currentTimeMillis();
for (var pathObject : pathObjects) {
ROI pathROI = pathObject.getROI();
if (pathROI instanceof PolygonROI) {
PolygonROI polygonROI = (PolygonROI) pathROI;
pathROI = ShapeSimplifier.simplifyPolygon(polygonROI, altitudeThreshold);
} else {
pathROI = ShapeSimplifier.simplifyShape(pathROI, altitudeThreshold);
}
((PathAnnotationObject) pathObject).setROI(pathROI);
}
long endTime = System.currentTimeMillis();
logger.debug("Shapes simplified in " + (endTime - startTime) + " ms");
hierarchy.fireObjectsChangedEvent(hierarchy, pathObjects);
}
Aggregations