/** * Add a pixel into this connected component. If the pixel is not adjacent * to another pixel within this connected component, then some methods may * return unexpected results. Side-affects this object. * * @param x * The x-coordinate of the pixel to add * @param y * The y-coordinate of the pixel to add */ public void addPixel(int x, int y) { addPixel(new Pixel(x, y)); }
/** * Construct a contour with the given type and start at the origin * * @param type * the type */ public Contour(ContourType type) { this.type = type; this.start = new Pixel(0, 0); }
private ConnectedComponent searchPixel(Pixel p, List<ConnectedComponent> components) { for (final ConnectedComponent c : components) { if (c.find(p)) return c; } return null; } },
/** * Calculates the centroid pixel of the connected component. That is, the * centroid value is rounded to the nearest pixel. * * @return A {@link Pixel} at the centroid. */ public Pixel calculateCentroidPixel() { final double[] centroid = calculateCentroid(); return new Pixel((int) Math.round(centroid[0]), (int) Math.round(centroid[1])); }
private static boolean isCentred(Set<Pixel> support) { final ConnectedComponent cc = new ConnectedComponent(support); final Pixel cp = cc.calculateCentroidPixel(); return cp.x == 0 && cp.y == 0; }
/** * Calculate the height and width of a box surrounding the component by * averaging the distances of pixels above and below the centroid. The * result is a double array where the first index is the height and the * second is the width. * * @return average height and width as a double array. */ public double[] calculateAverageHeightWidth() { return calculateAverageHeightWidth(calculateCentroid()); }
/** * Calculate the ratio of the area of this component's convex hull to the * actual area of this connected component. This gives an idea of how well * the calculated convex hull fits the component. The value returned is a * percentage (0-1). * * @return The area ratio of this component's convex hull its area. */ public double calculatePercentageConvexHullFit() { return calculateAreaRatio(calculateConvexHull()); }
/** * {@inheritDoc} * * @see java.lang.Object#toString() */ @Override public String toString() { return "ConnectedComponent(" + "area=" + calculateArea() + ")"; }
/** * Repositions the connected component so that its bounding box has its * origin at (0,0). Side-affects this connected component. */ public void reposition() { final Rectangle bb = this.calculateRegularBoundingBox(); translate(-(int) bb.x, -(int) bb.y); }
/** * Compute the aspect ratio of the regular bounding box. * * @return the aspect ratio of the regular bounding box. */ public double calculateRegularBoundingBoxAspectRatio() { final Rectangle bb = calculateRegularBoundingBox(); return bb.width / bb.height; }
@Override public PixelsFeature clone() { return (PixelsFeature) super.clone(); } }
@Override public void process(int x1, int x2, int y) { for (int x = x1; x <= x2; x++) ConnectedComponent.this.addPixel(x, y); } });
/** * Construct a new connected component from the given shape. Pixels are * created for the connected component that lie within the shape; but these * pixels will not have specific values as they are not associated to any * particular image. * * @param shape * The shape from which to construct the connected component. */ public ConnectedComponent(Shape shape) { fromShape(shape); }
/** * Calculates the convex hull polygon for this connected component using * Andrew's montone algorithm. * * @return The polygon defining the convex hull shape for this component. */ public Polygon calculateConvexHull() { return calculateConvexHull_AndrewsMontone(); }
/** * Add a pixel into this connected component. If the pixel is not adjacent * to another pixel within this connected component, then some methods may * return unexpected results. Side-affects this object. * * @param x * The x-coordinate of the pixel to add * @param y * The y-coordinate of the pixel to add */ public void addPixel(int x, int y) { addPixel(new Pixel(x, y)); }
/** * {@inheritDoc} */ @Override public Pixel clone() { return new Pixel(x, y); }
/** * Calculate the ratio of the area of this component's convex hull to the * actual area of this connected component. This gives an idea of how well * the calculated convex hull fits the component. The value returned is a * percentage (0-1). * * @return The area ratio of this component's convex hull its area. */ public double calculatePercentageConvexHullFit() { return calculateAreaRatio(calculateConvexHull()); }
/** * {@inheritDoc} * * @see java.lang.Object#toString() */ @Override public String toString() { return "ConnectedComponent(" + "area=" + calculateArea() + ")"; }
/** * Compute the aspect ratio of the regular bounding box. * * @return the aspect ratio of the regular bounding box. */ public double calculateRegularBoundingBoxAspectRatio() { final Rectangle bb = calculateRegularBoundingBox(); return bb.width / bb.height; }
/** * {@inheritDoc} */ @Override public Pixel clone() { return new Pixel(x, y); }