/** * 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; }
/** * 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 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); } } }
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; }
double [] centroid = cc.calculateCentroid(); double direction = cc.calculateDirection();
double [] centroid = cc.calculateCentroid(); double direction = cc.calculateDirection();
private static Map<Ellipse, OrientedFeatureVector> extractFeatures(FImage img) { final StrokeWidthTransform swt = new StrokeWidthTransform(false, 1.0f); final FImage swtImage = img.process(swt); DisplayUtilities.display(StrokeWidthTransform.normaliseImage(swtImage)); final EllipseGradientFeatureExtractor egfe = new EllipseGradientFeatureExtractor(); final List<ConnectedComponent> ccs = findComponents(swtImage); final Map<Ellipse, OrientedFeatureVector> im1f = new HashMap<Ellipse, OrientedFeatureVector>(); for (final ConnectedComponent cc : ccs) { final double[] centroid = cc.calculateCentroid(); final Matrix m = computeCovariance(cc, centroid); final Ellipse e = EllipseUtilities.ellipseFromCovariance((float) centroid[0], (float) centroid[1], m, 3f); for (final OrientedFeatureVector f : egfe.extract(img, e)) im1f.put(e, f); } return im1f; }
private static Map<Ellipse, OrientedFeatureVector> extractFeatures(FImage img) { final StrokeWidthTransform swt = new StrokeWidthTransform(false, 1.0f); final FImage swtImage = img.process(swt); DisplayUtilities.display(StrokeWidthTransform.normaliseImage(swtImage)); final EllipseGradientFeatureExtractor egfe = new EllipseGradientFeatureExtractor(); final List<ConnectedComponent> ccs = findComponents(swtImage); final Map<Ellipse, OrientedFeatureVector> im1f = new HashMap<Ellipse, OrientedFeatureVector>(); for (final ConnectedComponent cc : ccs) { final double[] centroid = cc.calculateCentroid(); final Matrix m = computeCovariance(cc, centroid); final Ellipse e = EllipseUtilities.ellipseFromCovariance((float) centroid[0], (float) centroid[1], m, 3f); for (final OrientedFeatureVector f : egfe.extract(img, e)) im1f.put(e, f); } return im1f; }
@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) { 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; }