public static List<PathObject> getLabelledObjectsForClass(final PathObjectHierarchy hierarchy, final PathClass pathClass) { List<PathObject> pathObjects = new ArrayList<>(); for (PathObject pathObject : getAnnotations(hierarchy)) { if (pathClass.equals(pathObject.getPathClass())) hierarchy.getDescendantObjects(pathObject, pathObjects, PathDetectionObject.class); } return pathObjects; }
public static List<PathObject> getConvexHullDetections(final PathObjectHierarchy hierarchy, final PathObject parent, final int nIterations) { Map<Point2, PathObject> pointsMap = new HashMap<>(); List<PathObject> convexDetections = new ArrayList<>(); List<PathObject> pathObjects = hierarchy.getDescendantObjects(parent, null, PathDetectionObject.class); if (pathObjects.isEmpty()) return Collections.emptyList(); // Populate the points map pointsMap.clear(); for (PathObject child : pathObjects) { if (!child.hasROI()) continue; pointsMap.put(new Point2(child.getROI().getCentroidX(), child.getROI().getCentroidY()), child); } // Determine what to remove List<Point2> points = new ArrayList<>(pointsMap.keySet()); for (int i = 0; i < nIterations; i++) { List<Point2> convexPoints = ConvexHull.getConvexHull(points); if (convexPoints != null) { for (Point2 p : convexPoints) convexDetections.add(pointsMap.get(p)); points.removeAll(convexPoints); } } return convexDetections; }
@Override protected void addRunnableTasks(final ImageData<T> imageData, final PathObject parentObject, List<Runnable> tasks) { ParameterList params = getParameterList(imageData); if (params.getBooleanParameterValue("clearAnnotations")) { PathObjectHierarchy hierarchy = imageData.getHierarchy(); List<PathObject> annotations = hierarchy.getDescendantObjects(parentObject, null, PathAnnotationObject.class); hierarchy.removeObjects(annotations, true); } tasks.add(new ClassificationToAnnotationRunnable(params, imageData, parentObject)); }
public static void runClassifier(final PathObjectHierarchy hierarchy, final PathObjectClassifier classifier) { // Apply classifier to everything // If we have a TMA grid, do one core at a time long startTime = System.currentTimeMillis(); TMAGrid tmaGrid = hierarchy.getTMAGrid(); List<PathObject> pathObjects = new ArrayList<>(); int nClassified = 0; // tmaGrid = null; if (tmaGrid != null) { for (TMACoreObject core : tmaGrid.getTMACoreList()) { pathObjects = hierarchy.getDescendantObjects(core, pathObjects, PathDetectionObject.class); nClassified += classifier.classifyPathObjects(pathObjects); pathObjects.clear(); } } else { pathObjects = hierarchy.getObjects(null, PathDetectionObject.class); nClassified = classifier.classifyPathObjects(pathObjects); } long endTime = System.currentTimeMillis(); logger.info(String.format("Classification time: %.2f seconds", (endTime-startTime)/1000.)); // Fire a change event for all detection objects if (nClassified > 0) hierarchy.fireObjectClassificationsChangedEvent(classifier, hierarchy.getObjects(null, PathDetectionObject.class)); else logger.warn("No objects classified!"); }