/** * Get the ROI of the selected object, if available, or null * @return */ public ROI getSelectedROI() { if (pathObjectSelected != null) return pathObjectSelected.getROI(); return null; }
public boolean isPoint() { return getROI() instanceof PointsROI; // TODO: Check the 'isPoint' method of PathObject }
public boolean hasROI() { return getROI() != null; }
/** * Test whether the ROI associated with one object can completely the ROI of a second object. * Returns false if either ROI is null. * * @param parentROI * @param childROI * @return */ public static boolean containsObject(PathObject parentObject, PathObject childObject) { if (parentObject == null || childObject == null) return false; return containsROI(parentObject.getROI(), childObject.getROI()); }
/** * Filter a collection by removing objects if their ROIs are not instances of a specified class. * * @param pathObjects * @param cls */ public static void filterROIs(final Collection<PathObject> pathObjects, final Class<? extends ROI> cls) { Iterator<PathObject> iter = pathObjects.iterator(); while (iter.hasNext()) { ROI pathROI = iter.next().getROI(); if (!cls.isInstance(pathROI)) iter.remove(); } }
public static ROI getSelectedROI() { PathObject pathObject = getSelectedObject(); if (pathObject != null) return pathObject.getROI(); return null; }
public static <T> Runnable createRunnableTask(final ObjectDetector<T> task, final ParameterList params, final ImageData<T> imageData, final PathObject parentObject) { return createRunnableTask(task, params, imageData, parentObject, parentObject.getROI(), 0); }
/** * Get the ROI for a PathObject, with a preference for the nucleus ROI of a cell. * * @param pathObject * @param preferNucleus * @return */ public static ROI getROI(final PathObject pathObject, final boolean preferNucleus) { if (preferNucleus && pathObject instanceof PathCellObject) { ROI roi = ((PathCellObject)pathObject).getNucleusROI(); if (roi != null) return roi; } return pathObject.getROI(); }
@Override public int compare(PathObject o1, PathObject o2) { double x1 = o1.getROI().getCentroidX(); double x2 = o2.getROI().getCentroidX(); // int value = Double.compare(x1, x2); // if (value == 0) { // System.out.println(x1 + " vs. " + x2); // System.out.println(String.format("(%.2f, %.2f) vs (%.2f, %.2f)", o1.getROI().getCentroidX(), o1.getROI().getCentroidY(), o2.getROI().getCentroidX(), o2.getROI().getCentroidY())); } return Double.compare(x1, x2); // if (x1 > x2) // return 1; // if (x2 < x1) // return -1; // System.out.println(x1 + " vs. " + x2); // System.out.println(String.format("(%.2f, %.2f) vs (%.2f, %.2f)", o1.getROI().getCentroidX(), o1.getROI().getCentroidY(), o2.getROI().getCentroidX(), o2.getROI().getCentroidY())); // return 0; // return (int)Math.signum(o1.getROI().getCentroidX() - o2.getROI().getCentroidX()); } });
protected String objectCountPostfix() { ROI pathROI = getROI(); if (pathROI instanceof PathPoints) { int nPoints = ((PathPoints)pathROI).getNPoints(); if (nPoints == 1) return " - 1 point"; else return String.format(" - %d points", nPoints); } if (!hasChildren()) return ""; if (childList.size() == 1) return " - 1 object"; else return " - " + childList.size() + " objects"; }
public static Collection<PathObject> getObjectsForLocation(final PathObjectHierarchy hierarchy, final double x, final double y, final int zPos, final int tPos) { if (hierarchy == null) return Collections.emptyList(); Set<PathObject> pathObjects = new HashSet<>(8); hierarchy.getObjectsForRegion(PathObject.class, ImageRegion.createInstance((int)x, (int)y, 1, 1, zPos, tPos), pathObjects); removePoints(pathObjects); // Ensure we don't have any PointROIs // Ensure the ROI contains the click Iterator<PathObject> iter = pathObjects.iterator(); while (iter.hasNext()) { PathObject temp = iter.next(); // if ((temp.isHidden() && temp.hasChildren()) || !PathROIHelpers.areaContains(temp.getROI(), x, y)) if (!ROIHelpers.areaContains(temp.getROI(), x, y)) iter.remove(); } if (pathObjects.isEmpty()) { return Collections.emptyList(); } return pathObjects; }
@Override public void run() { try { MeasurementList measurementList = parentObject.getMeasurementList(); ROI roi; if (parentObject instanceof PathCellObject) { roi = ((PathCellObject)parentObject).getNucleusROI(); if (roi instanceof PathArea) addMeasurements(measurementList, (PathArea)roi, "Nucleus Shape: ", pixelWidth, pixelHeight, unit, doArea, doPerimeter, doCircularity); roi = parentObject.getROI(); if (roi instanceof PathArea) addMeasurements(measurementList, (PathArea)roi, "Cell Shape: ", pixelWidth, pixelHeight, unit, doArea, doPerimeter, doCircularity); } else { roi = parentObject.getROI(); if (roi instanceof PathArea) addMeasurements(measurementList, (PathArea)roi, "ROI Shape: ", pixelWidth, pixelHeight, unit, doArea, doPerimeter, doCircularity); } measurementList.closeList(); } catch (Exception e) { e.printStackTrace(); throw(e); } } });
if (!pathObject.isPoint()) continue; PointsROI points = (PointsROI)pathObject.getROI(); ZipEntry e = new ZipEntry(String.format("Points %d.txt", ++ind)); out.putNextEntry(e);
/** * Get all the objects whose bounding box intersects with a specified region * @param region * @return */ List<PathObject> getObjectsForRegion(Rectangle2D region) { List<PathObject> pathObjects = new ArrayList<>(); for (PathObject child : getChildObjects()) { ROI childROI = child.getROI(); if (childROI instanceof PathArea && region.intersects(getBounds2D(childROI))) { pathObjects.add(child); } } 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 public String toString() { String postfix; if (getPathClass() == null) postfix = objectCountPostfix(); else postfix = " (" + getPathClass().getName() + ")"; if (getName() != null) return getName() + postfix; if (getROI() != null) return getROI().toString() + postfix; return "Unassigned" + postfix; // Entire image }
@Override public void run() { ROI roi = parentObject.getROI(); if (!(roi instanceof PathArea)) { lastMessage = "Cannot tile ROI " + roi + " - does not represent an area region of interest";
public static Collection<? extends ROI> computeTiledROIs(ImageData<?> imageData, PathObject parentObject, ImmutableDimension sizePreferred, ImmutableDimension sizeMax, boolean fixedSize, int overlap) { ROI parentROI = parentObject.getROI(); if (parentROI == null) parentROI = new RectangleROI(0, 0, imageData.getServer().getWidth(), imageData.getServer().getHeight()); return computeTiledROIs(parentROI, sizePreferred, sizeMax, fixedSize, overlap); }
/** * Add a pathObject to the map. * If it does not have a ROI, it will be ignored. * Otherwise it is added to the map for as many tiles as its ROI's bounding box intersects. * * @param pathObject */ public void put(PathObject pathObject) { if (!pathObject.hasROI()) return; // if (pathObject.isPoint()) { // PathPointsROI points = (PathPointsROI)pathObject.getROI(); // } // Compute the tiles & add as required ROI pathROI = pathObject.getROI(); int tx1 = (int)(pathROI.getBoundsX() / tileSize); int ty1 = (int)(pathROI.getBoundsY() / tileSize); int tx2 = (int)((pathROI.getBoundsX() + pathROI.getBoundsWidth()) / tileSize); int ty2 = (int)((pathROI.getBoundsY() + pathROI.getBoundsHeight()) / tileSize); int z = pathROI.getZ(); int t = pathROI.getT(); for (int y = ty1; y <= ty2; y++) { for (int x = tx1; x <= tx2; x++) { putInMap(getKey(x, y, z, t), pathObject); } } }