public static PathShape getShapeROI(Area area, int c, int z, int t) { return getShapeROI(area, c, z, t, -1); }
/** * Get a PathShape from an Area. * This will try to return a PathRectangleROI or PathPolygonROI if possible, * or PathAreaROI if neither of the other classes can adequately represent the area. * * In the input shape is an Ellipse2D then an EllipseROI will be returned. * * @param area * @param c * @param z * @param t * @param flatness - can be used to prefer polygons, see Shape.getPathIterator(AffineTransform at, double flatness) * @return */ public static PathShape getShapeROI(Shape shape, int c, int z, int t, double flatness) { if (shape instanceof Rectangle2D) { Rectangle2D bounds = shape.getBounds2D(); return new RectangleROI(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), c, z, t); } if (shape instanceof Ellipse2D) { Rectangle2D bounds = shape.getBounds2D(); return new EllipseROI(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), c, z, t); } return getShapeROI(new Area(shape), c, z, t, flatness); }
/** * Dilate or erode a ROI using a circular structuring element. * * @param roi The ROI to dilate or erode. * @param radius The radius of the structuring element to use. If positive this will be a dilation, if negative an erosion. * @return */ public static PathShape roiMorphology(final ROI roi, final double radius) { return getShapeROI(shapeMorphology(getShape(roi), radius), roi.getC(), roi.getZ(), roi.getT()); }
ROI parentROI = parentObject.getROI(); if (parentROI != null) pathROINew = PathROIToolsAwt.getShapeROI(new Area(path), parentROI.getC(), parentROI.getZ(), parentROI.getT()); else pathROINew = PathROIToolsAwt.getShapeROI(new Area(path), -1, 0, 0); pathSingleAnnotation = new PathAnnotationObject(pathROINew, pathClass); if (!deleteTiles)
if (op == PathROIToolsAwt.CombineOp.SUBTRACT) { areaTemp.subtract(areaNew); PathShape shapeNew = PathROIToolsAwt.getShapeROI(areaTemp, shapeMask.getC(), shapeMask.getZ(), shapeMask.getT()); annotationNew = new PathAnnotationObject(shapeNew, temp.getPathClass()); } else if (op == PathROIToolsAwt.CombineOp.INTERSECT) { areaTemp.intersect(areaNew); PathShape shapeNew = PathROIToolsAwt.getShapeROI(areaTemp, shapeMask.getC(), shapeMask.getZ(), shapeMask.getT()); annotationNew = new PathAnnotationObject(shapeNew, temp.getPathClass()); } else { PathShape shapeNew = PathROIToolsAwt.getShapeROI(areaNew, shapeMask.getC(), shapeMask.getZ(), shapeMask.getT()); objectsToAdd.add(new PathAnnotationObject(shapeNew, pathObject.getPathClass()));
public static PathShape combineROIs(PathShape shape1, PathShape shape2, CombineOp op, double flatness) { // Check we can combine if (!ROIHelpers.sameImagePlane(shape1, shape2)) throw new IllegalArgumentException("Cannot combine - shapes " + shape1 + " and " + shape2 + " do not share the same image plane"); Area area1 = getArea(shape1); Area area2 = getArea(shape2); // Do a quick check to see if a combination might be avoided if (op == CombineOp.INTERSECT) { if (area1.contains(area2.getBounds2D())) return shape2; if (area2.contains(area1.getBounds2D())) return shape1; } else if (op == CombineOp.ADD) { if (area1.contains(area2.getBounds2D())) return shape1; if (area2.contains(area1.getBounds2D())) return shape2; } combineAreas(area1, area2, op); // I realise the following looks redundant... however direct use of the areas with the // brush tool led to strange artefacts appearing & disappearing... performing an additional // conversion seems to help // area1 = new Area(new Path2D.Float(area1)); // Return simplest ROI that works - prefer a rectangle or polygon over an area return getShapeROI(area1, shape1.getC(), shape1.getZ(), shape1.getT(), flatness); }
ROI roi2 = PathROIToolsAwt.getShapeROI(area, roi.getC(), roi.getZ(), roi.getT(), 0.5);