private static List<PathObject> getAnnotations(PathObjectHierarchy hierarchy) { if (hierarchy == null) return Collections.emptyList(); else return hierarchy.getObjects(null, PathAnnotationObject.class); }
/** * Get a flattened list containing all PathObjects in the hierarchy (apart from the root object). * * @param list - optional list into which the objects should be added (may be null) * @return */ public synchronized List<PathObject> getFlattenedObjectList(List<PathObject> list) { if (list == null) list = new ArrayList<>(nObjects()); getObjects(list, PathObject.class); return list; }
public static List<PathObject> getDetectionObjects() { PathObjectHierarchy hierarchy = getCurrentHierarchy(); if (hierarchy == null) return Collections.emptyList(); return hierarchy.getObjects(null, PathDetectionObject.class); }
public synchronized List<PathObject> getPointObjects(Class<? extends PathObject> cls) { List<PathObject> pathObjects = getObjects(null, cls); if (!pathObjects.isEmpty()) { Iterator<PathObject> iter = pathObjects.iterator(); while (iter.hasNext()) { if (!iter.next().isPoint()) { iter.remove(); } } } return pathObjects; }
public static List<PathObject> getCellObjects() { PathObjectHierarchy hierarchy = getCurrentHierarchy(); if (hierarchy == null) return Collections.emptyList(); return hierarchy.getObjects(null, PathCellObject.class); }
public static List<PathObject> getAnnotationObjects() { PathObjectHierarchy hierarchy = getCurrentHierarchy(); if (hierarchy == null) return Collections.emptyList(); return hierarchy.getObjects(null, PathAnnotationObject.class); }
public static Set<String> getAvailableFeatures(final PathObjectHierarchy hierarchy, final Class<? extends PathObject> cls) { if (hierarchy == null) return Collections.emptySet(); return getAvailableFeatures(hierarchy.getObjects(null, cls)); }
/** * Get a set of the represented path classes, i.e. those with at least 1 manually-labelled object. * * @return */ public static Set<PathClass> getRepresentedPathClasses(final PathObjectHierarchy hierarchy, final Class<? extends PathObject> cls) { Set<PathClass> pathClassSet = new LinkedHashSet<>(); for (PathObject pathObject : hierarchy.getObjects(null, cls)) { if (pathObject.getPathClass() != null) pathClassSet.add(pathObject.getPathClass()); } return pathClassSet; }
public static void setIntensityClassifications(final PathObjectHierarchy hierarchy, final Class<? extends PathObject> cls, final String measurementName, final double... thresholds) { List<PathObject> pathObjects = hierarchy.getObjects(null, cls); setIntensityClassifications(pathObjects, measurementName, thresholds); hierarchy.fireObjectClassificationsChangedEvent(QP.class, pathObjects); }
@Override protected Collection<PathObject> getParentObjects(final PluginRunner<BufferedImage> runner) { return runner.getImageData().getHierarchy().getObjects(null, PathDetectionObject.class); }
/** * Reset the intensity classifications for all detections in the specified hierarchy. * * This means setting the classification to the result of <code>getNonIntensityAncestorPathClass(pathObject)</code> * * @param hierarchy */ public static void resetIntensityClassifications(final PathObjectHierarchy hierarchy) { List<PathObject> pathObjects = hierarchy.getObjects(null, PathDetectionObject.class); resetIntensityClassifications(pathObjects); hierarchy.fireObjectClassificationsChangedEvent(QP.class, pathObjects); }
@Override protected Collection<PathObject> getParentObjects(final PluginRunner<BufferedImage> runner) { return runner.getImageData().getHierarchy().getObjects(null, PathDetectionObject.class); }
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!"); }
public static void classifyDetection(final Predicate<PathObject> p, final String className) { PathObjectHierarchy hierarchy = getCurrentHierarchy(); if (hierarchy == null) return; List<PathObject> reclassified = new ArrayList<>(); PathClass pathClass = PathClassFactory.getPathClass(className); for (PathObject pathObject : hierarchy.getObjects(null, PathDetectionObject.class)) { if (p.test(pathObject) && pathObject.getPathClass() != pathClass) { pathObject.setPathClass(pathClass); reclassified.add(pathObject); } } if (!reclassified.isEmpty()) hierarchy.fireObjectClassificationsChangedEvent(QP.class, reclassified); }
/** * Reset the PathClass for all objects of the specified type in the specified hierarchy. * * @param hierarchy * @param cls */ public static void resetClassifications(final PathObjectHierarchy hierarchy, final Class<? extends PathObject> cls) { if (hierarchy == null) return; List<PathObject> objects = hierarchy.getObjects(null, cls); if (objects.isEmpty()) { logger.warn("No objects to reset classifications!"); return; } for (PathObject pathObject : objects) { if (pathObject.getPathClass() != null) pathObject.setPathClass(null); } hierarchy.fireObjectClassificationsChangedEvent(QP.class, objects); }
public static void removeMeasurements(final PathObjectHierarchy hierarchy, final Class<? extends PathObject> cls, final String... measurementNames) { if (hierarchy == null) return; List<PathObject> pathObjects = hierarchy.getObjects(null, cls); for (PathObject pathObject : pathObjects) { // A little check, to handle possible subclasses being returned if (pathObject.getClass() != cls) continue; // Remove the measurements pathObject.getMeasurementList().removeMeasurements(measurementNames); pathObject.getMeasurementList().closeList(); } hierarchy.fireObjectMeasurementsChangedEvent(null, pathObjects); }
public static void clearAllObjects(final Class<? extends PathObject> cls) { if (cls == null) { clearAllObjects(); return; } PathObjectHierarchy hierarchy = getCurrentHierarchy(); if (hierarchy == null) return; List<PathObject> pathObjects = hierarchy.getObjects(null, cls); hierarchy.removeObjects(pathObjects, true); PathObject selected = hierarchy.getSelectionModel().getSelectedObject(); if (selected != null && selected.getClass().isAssignableFrom(cls)) hierarchy.getSelectionModel().setSelectedObject(null); }