@Override public void process(ConnectedComponent cc) { area = cc.calculateArea(); final double[] c = cc.calculateCentroid(); cx = c[0]; cy = c[1]; direction = cc.calculateDirection(); elongatedness = cc.calculateOrientatedBoundingBoxAspectRatio(); final float edge_length = cc.getOuterBoundary().size(); compactness = (edge_length * edge_length) / new ConnectedComponent(cc.toPolygon()).calculateArea(); if (area > 4) chfit = new ConnectedComponent(cc.toPolygon()).calculatePercentageConvexHullFit(); // chfit // won't // work // for // really // small // regions else chfit = 1; if (area > 100) cornerEst = cc.estimateNumberOfVertices(3, 10); else cornerEst = area; }
@Override public void process(ConnectedComponent cc) { // Dilate a connected component final Rectangle cc_bb = cc.calculateRegularBoundingBox(); final Set<Pixel> newPixels = new HashSet<Pixel>(); for (int j = (int) (cc_bb.y - sh); j <= cc_bb.y + sh + cc_bb.height; j++) { for (int i = (int) (cc_bb.x - sw); i <= cc_bb.x + sw + cc_bb.width; i++) { final Pixel p = new Pixel(i, j); if (element.intersect(p, cc.getPixels()).size() >= 1) { newPixels.add(p); } } } cc.getPixels().addAll(newPixels); }
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 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()); }
/** * Calculate the ratio of the area of the given polygon to the area of this * connected component. This does not consider whether the areas overlap. * * @param ch * The polygon to test again. * @return The area ratio of the given polygon to this connected component. */ public double calculateAreaRatio(Polygon ch) { return calculateAreaRatio(new ConnectedComponent(ch)); }
protected ConnectedComponent floodFill(FImage image, Pixel start, int[][] output, int color) { final ConnectedComponent cc = new ConnectedComponent(); cc.addPixel(i, n.y);
@Override public void process(ConnectedComponent cc) { cc = new ConnectedComponent(cc.calculateConvexHull()); //make shape convex List<Pixel> bound = cc.getInnerBoundary(ConnectMode.CONNECT_8); double [] centroid = cc.calculateCentroid(); double direction = cc.calculateDirection();
Polygon ch = cc.calculateConvexHull(); ConnectedComponent chcc = new ConnectedComponent(ch); chcc.process(new BlobRenderer<Float>(image, shade.get(ConfigurableRenderOptions.CH_BLOB))); cc.process(new BlobRenderer<Float>(image, shade.get(ConfigurableRenderOptions.BLOB))); cc.process(new BorderRenderer<Float>(image, shade.get(ConfigurableRenderOptions.BLOB), ConnectMode.CONNECT_8)); chcc.process(new CentroidRenderer<Float>(image, shade.get(ConfigurableRenderOptions.CH_CENTROID))); cc.process(new CentroidRenderer<Float>(image, shade.get(ConfigurableRenderOptions.CENTROID))); chcc.process(new AxisRenderer<Float>(image, shade.get(ConfigurableRenderOptions.CH_AXIS))); cc.process(new AxisRenderer<Float>(image, shade.get(ConfigurableRenderOptions.AXIS)));
protected ConnectedComponent c(FImage mask) { return new ConnectedComponent(mask, 0.5f); }
protected List<CCDetectedFace> extractFaces(FImage faceMap, FImage skinMap, FImage image) { final List<ConnectedComponent> blobs = ccl.findComponents(faceMap); final List<CCDetectedFace> faces = new ArrayList<CCDetectedFace>(); for (final ConnectedComponent blob : blobs) { if (blob.calculateArea() > 1000) { final double[] centroid = blob.calculateCentroid(); final double[] hw = blob.calculateAverageHeightWidth(centroid); final double percentageSkin = calculatePercentageSkin(skinMap, (int) Math.round(centroid[0] - (hw[0] / 2)), (int) Math.round(centroid[1] - (hw[1] / 2)), (int) Math.round(centroid[0] + (hw[0] / 2)), (int) Math.round(centroid[1] + (hw[1] / 2))); final double ratio = hw[0] / hw[1]; if (Math.abs(ratio - GOLDEN_RATIO) < goldenRatioThreshold && percentageSkin > percentageThreshold) { final Rectangle r = blob.calculateRegularBoundingBox(); faces.add(new CCDetectedFace( r, image.extractROI(r), blob, (float) ((percentageSkin / percentageThreshold) * (Math.abs(ratio - GOLDEN_RATIO) / goldenRatioThreshold)))); } } } return faces; }
/** * Render a connected component with a given grey level and display it * * @param input * the connected component * @param col * the grey level * @return frame containing the rendered image */ public static JFrame display(final ConnectedComponent input, final float col) { final ConnectedComponent cc = input.clone(); final Rectangle bb = cc.calculateRegularBoundingBox(); // Render the mask, leaving a 10 px border cc.translate(10 - (int) bb.x, 10 - (int) bb.y); final FImage mask = new FImage((int) Math.max(bb.width + 20, 100), (int) Math.max(bb.height + 20, 100)); final BlobRenderer<Float> br = new BlobRenderer<Float>(mask, 1.0F); cc.process(br); return DisplayUtilities.display(mask); }
if (cc.calculateArea() > big.calculateArea()) big = cc; if (big.calculateArea() > 500) { frame.drawShape(big.toPolygon(), RGBColour.RED); final Point2d pt = big.calculateCentroidPixel();
/** * Calculate the ratio of the area of the given connected component to the * area of the connected component. This does not consider whether the areas * overlap. * * @param ch * The connected component to test. * @return The area ratio of the given connected component to this connected * component. */ public double calculateAreaRatio(ConnectedComponent ch) { return (double) calculateArea() / (double) ch.calculateArea(); }
currentComponent = cc; } else if (currentComponent != cc) { currentComponent.merge(cc); components.remove(cc); currentComponent = new ConnectedComponent(); components.add(currentComponent); currentComponent.addPixel(x, y);
final Rectangle bb = cc.calculateRegularBoundingBox(); if (bb.width < 0.4 * i1.width || bb.calculateArea() / cc.calculateArea() > 2) { if (bb.x < left) left = (int) bb.x;
@Override public Shape getShape() { return connectedComponent.toPolygon(); } }
/** * {@inheritDoc} * @see org.openimaj.image.processor.connectedcomponent.ConnectedComponentProcessor#process(org.openimaj.image.pixel.ConnectedComponent) */ @Override public void process(ConnectedComponent cc) { if (fill) image.drawShapeFilled(cc.calculateRegularBoundingBox(), colour); else image.drawShape(cc.calculateRegularBoundingBox(), colour); } }
/** * Calculates the distance from the centroid of every pixel on the * 8-connected boundary of this component. Returns a {@link TFloatArrayList} * that contains the list of distances (in order of the boundary). * * @return A list ({@link TFloatArrayList}) of distances of boundary points * to the centroid. */ public TFloatArrayList calculateBoundaryDistanceFromCentre() { final TFloatArrayList distances = new TFloatArrayList(); final List<Pixel> bound = getInnerBoundary(ConnectMode.CONNECT_8); final double[] centroid = calculateCentroid(); for (final Pixel p : bound) { final float dist = (float) Math.sqrt(((centroid[0] - p.x) * ((centroid[0] - p.x))) + ((centroid[1] - p.y) * ((centroid[1] - p.y)))); distances.add(dist); } return distances; }
/** * Draws the component's centroid into the image as a small 5 pixel square * centred on the centroid. * * {@inheritDoc} * @see org.openimaj.image.processor.connectedcomponent.ConnectedComponentProcessor#process(org.openimaj.image.pixel.ConnectedComponent) */ @Override public void process(ConnectedComponent cc) { double [] centroid = cc.calculateCentroid(); for (int i=-5; i<=5; i++) { int y = (int)(Math.round(centroid[1])); int x = (int)(Math.round(centroid[0])); if (i+x>0 && i+x<image.getWidth()) image.setPixel(x+i, y, colour); if (i+y>0 && i+y<image.getHeight()) image.setPixel(x, y+i, colour); } } }
/** * Draws the principle axes of the connected component into the image. * * {@inheritDoc} * @see org.openimaj.image.processor.connectedcomponent.ConnectedComponentProcessor#process(org.openimaj.image.pixel.ConnectedComponent) */ @Override public void process(ConnectedComponent cc) { Pixel cp = cc.calculateCentroidPixel(); double theta = cc.calculateDirection(); ImageRenderer<T, ?> r = image.createRenderer(); r.drawLine(cp.x, cp.y, theta, majorSize, colour); r.drawLine(cp.x, cp.y, theta, -majorSize, colour); r.drawLine(cp.x, cp.y, (Math.PI/2.0)+theta, minorSize, colour); r.drawLine(cp.x, cp.y, (Math.PI/2.0)+theta, -minorSize, colour); } }