Search in sources :

Example 1 with Contour

use of boofcv.alg.filter.binary.Contour in project BoofCV by lessthanoptimal.

the class VisualizeBinaryData method render.

/**
 * Renders only the external contours.  Each contour is individually colored as specified by 'colors'
 *
 * @param contours List of contours
 * @param colors List of RGB colors for each element in contours.  If null then random colors will be used.
 * @param out (Optional) Storage for output
 */
public static void render(List<Contour> contours, int[] colors, BufferedImage out) {
    colors = checkColors(colors, contours.size());
    for (int i = 0; i < contours.size(); i++) {
        Contour c = contours.get(i);
        int color = colors[i];
        for (Point2D_I32 p : c.external) {
            out.setRGB(p.x, p.y, color);
        }
    }
}
Also used : EdgeContour(boofcv.alg.feature.detect.edge.EdgeContour) Contour(boofcv.alg.filter.binary.Contour) Point2D_I32(georegression.struct.point.Point2D_I32)

Example 2 with Contour

use of boofcv.alg.filter.binary.Contour in project BoofCV by lessthanoptimal.

the class VisualizeBinaryData method renderContours.

/**
 * Draws contours. Internal and external contours are different user specified colors.
 *
 * @param contours List of contours
 * @param colorExternal RGB color
 * @param colorInternal RGB color
 * @param width Image width
 * @param height Image height
 * @param out (Optional) storage for output image
 * @return Rendered contours
 */
public static BufferedImage renderContours(List<Contour> contours, int colorExternal, int colorInternal, int width, int height, BufferedImage out) {
    if (out == null) {
        out = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    } else {
        Graphics2D g2 = out.createGraphics();
        g2.setColor(Color.BLACK);
        g2.fillRect(0, 0, width, height);
    }
    for (Contour c : contours) {
        for (Point2D_I32 p : c.external) {
            out.setRGB(p.x, p.y, colorExternal);
        }
        for (List<Point2D_I32> l : c.internal) {
            for (Point2D_I32 p : l) {
                out.setRGB(p.x, p.y, colorInternal);
            }
        }
    }
    return out;
}
Also used : EdgeContour(boofcv.alg.feature.detect.edge.EdgeContour) Contour(boofcv.alg.filter.binary.Contour) Point2D_I32(georegression.struct.point.Point2D_I32)

Example 3 with Contour

use of boofcv.alg.filter.binary.Contour in project BoofCV by lessthanoptimal.

the class VisualizeBinaryData method renderContours.

/**
 * Draws contours. Internal and external contours are different user specified colors.
 *
 * @param contours List of contours
 * @param colorExternal (Optional) Array of RGB colors for each external contour
 * @param colorInternal RGB color
 * @param width Image width
 * @param height Image height
 * @param out (Optional) storage for output image
 * @return Rendered contours
 */
public static BufferedImage renderContours(List<Contour> contours, int[] colorExternal, int colorInternal, int width, int height, BufferedImage out) {
    if (out == null) {
        out = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    } else {
        Graphics2D g2 = out.createGraphics();
        g2.setColor(Color.BLACK);
        g2.fillRect(0, 0, width, height);
    }
    colorExternal = checkColors(colorExternal, contours.size());
    int index = 0;
    for (Contour c : contours) {
        int color = colorExternal[index++];
        for (Point2D_I32 p : c.external) {
            out.setRGB(p.x, p.y, color);
        }
        for (List<Point2D_I32> l : c.internal) {
            for (Point2D_I32 p : l) {
                out.setRGB(p.x, p.y, colorInternal);
            }
        }
    }
    return out;
}
Also used : EdgeContour(boofcv.alg.feature.detect.edge.EdgeContour) Contour(boofcv.alg.filter.binary.Contour) Point2D_I32(georegression.struct.point.Point2D_I32)

Example 4 with Contour

use of boofcv.alg.filter.binary.Contour in project BoofCV by lessthanoptimal.

the class VisualizeBinaryData method render.

public static void render(List<Contour> contours, Color internal, Color external, double scale, Graphics2D g2) {
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Line2D.Double l = new Line2D.Double();
    g2.setStroke(new BasicStroke(Math.max(1, (float) scale)));
    for (Contour c : contours) {
        if (external != null) {
            g2.setColor(external);
            renderContour(scale, g2, l, c.external);
        }
        if (internal != null) {
            g2.setColor(internal);
            for (List<Point2D_I32> inner : c.internal) {
                renderContour(scale, g2, l, inner);
            }
        }
    }
    if (scale > 4) {
        Color before = g2.getColor();
        g2.setStroke(new BasicStroke(1));
        g2.setColor(Color.LIGHT_GRAY);
        for (Contour c : contours) {
            if (external != null) {
                renderContour(scale, g2, l, c.external);
            }
            if (internal != null) {
                for (List<Point2D_I32> inner : c.internal) {
                    renderContour(scale, g2, l, inner);
                }
            }
        }
        g2.setColor(before);
    }
}
Also used : EdgeContour(boofcv.alg.feature.detect.edge.EdgeContour) Contour(boofcv.alg.filter.binary.Contour) Point2D_I32(georegression.struct.point.Point2D_I32) Line2D(java.awt.geom.Line2D)

Example 5 with Contour

use of boofcv.alg.filter.binary.Contour in project BoofCV by lessthanoptimal.

the class ShowEdgeContourApp method doProcess.

private void doProcess() {
    if (input == null)
        return;
    final BufferedImage temp;
    if (activeAlg == 0) {
        if (previousBlur != barCanny.getBlurRadius()) {
            previousBlur = barCanny.getBlurRadius();
            canny = FactoryEdgeDetectors.canny(previousBlur, true, true, imageType, derivType);
        }
        double thresh = barCanny.getThreshold() / 100.0;
        canny.process(workImage, (float) thresh * 0.1f, (float) thresh, null);
        List<EdgeContour> contours = canny.getContours();
        temp = VisualizeBinaryData.renderContours(contours, null, workImage.width, workImage.height, null);
    } else {
        // create a binary image by thresholding
        GThresholdImageOps.threshold(workImage, binary, barBinary.getThreshold(), barBinary.isDown());
        contour.process(binary, labeled);
        List<Contour> contours = BinaryImageOps.convertContours(contour);
        temp = VisualizeBinaryData.renderContours(contours, null, 0xFF1010, workImage.width, workImage.height, null);
    }
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            panel.setImage(temp);
            panel.repaint();
        }
    });
}
Also used : Contour(boofcv.alg.filter.binary.Contour) EdgeContour(boofcv.alg.feature.detect.edge.EdgeContour) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) EdgeContour(boofcv.alg.feature.detect.edge.EdgeContour)

Aggregations

Contour (boofcv.alg.filter.binary.Contour)14 EdgeContour (boofcv.alg.feature.detect.edge.EdgeContour)8 BufferedImage (java.awt.image.BufferedImage)8 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)6 GrayU8 (boofcv.struct.image.GrayU8)6 Point2D_I32 (georegression.struct.point.Point2D_I32)6 PointIndex_I32 (boofcv.struct.PointIndex_I32)5 GrayF32 (boofcv.struct.image.GrayF32)3 ListDisplayPanel (boofcv.gui.ListDisplayPanel)2 BinaryContourFinder (boofcv.abst.filter.binary.BinaryContourFinder)1 FitData (boofcv.alg.shapes.FitData)1 ConvertBufferedImage (boofcv.core.image.ConvertBufferedImage)1 GrayS16 (boofcv.struct.image.GrayS16)1 GrayS32 (boofcv.struct.image.GrayS32)1 EllipseRotated_F64 (georegression.struct.curve.EllipseRotated_F64)1 Line2D (java.awt.geom.Line2D)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Random (java.util.Random)1 Term (nars.term.Term)1