/** * Get a java.awt.geom.Area object representing a ROI. * * @param roi * @return */ public static Area getArea(final ROI roi) { Shape shape = getShape(roi); if (shape instanceof Area) return (Area)shape; return new Area(shape); }
/** * 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()); }
/** * Warning: Currently, this only compares the actual shape, *not* the channel, timepoint or z-slice. * However this may change in the future. * A * * TODO: Consider comparing channels, time-points & z-slices. */ public static boolean containsShape(final PathShape shape1, final PathShape shape2) { return containsShape(getShape(shape1), getShape(shape2)); }
Shape shape = PathROIToolsAwt.getShape(pathObject.getROI());
/** * Create a grayscale BufferedImage representing a mask for a specified ROI. * * Pixels inside the ROI will be 255, pixels outside will be 0. * * @param width Width of the requested mask image * @param height Height of the requested mask image * @param roi ROI for mask * @param xOrigin Pixel x coordinate of the top left of the region to include in the mask. * @param yOrigin Pixel y coordinate of the top left of the region to include in the mask. * @param downsample Downsample factor to use when generating the mask, i.e. the amoutn to scale. * @return */ public static BufferedImage createROIMask(final int width, final int height, final ROI roi, final double xOrigin, final double yOrigin, final double downsample) { BufferedImage imgMask = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); Shape shape = PathROIToolsAwt.getShape(roi); Graphics2D g2d = imgMask.createGraphics(); g2d.scale(1.0/downsample, 1.0/downsample); g2d.translate(-xOrigin, -yOrigin); g2d.setColor(Color.WHITE); g2d.fill(shape); // g2d.draw(shape); g2d.dispose(); return imgMask; }
Shape shape = getShape(pathArea); if (shape.contains(boundsTile)) pathROI = new RectangleROI(boundsTile.getX(), boundsTile.getY(), boundsTile.getWidth(), boundsTile.getHeight(), parentROI.getC(), parentROI.getZ(), parentROI.getT());
for (PathObject tempObject : overlapObjects) { if (tempObject.getROI() instanceof PathArea) { Shape shapeTemp = PathROIToolsAwt.getShape(tempObject.getROI()); Area areaTemp = new Area(shapeTemp); mapOld.put(areaTemp, tempObject);
/** * * Create a simplified shape (fewer coordinates) using method based on Visvalingam’s Algorithm. * * See references: * https://hydra.hull.ac.uk/resources/hull:8338 * https://www.jasondavies.com/simplify/ * http://bost.ocks.org/mike/simplify/ * * @param polygon * @param areaThreshold * @return */ public static PathShape simplifyShape(PathShape shapeROI, double altitudeThreshold) { Shape shape = PathROIToolsAwt.getShape(shapeROI); Path2D path = shape instanceof Path2D ? (Path2D)shape : new Path2D.Float(shape); path = simplifyPath(path, altitudeThreshold); // Construct a new polygon return new AWTAreaROI(path, shapeROI.getC(), shapeROI.getZ(), shapeROI.getT()); }