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);
}
}
}
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;
}
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;
}
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);
}
}
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();
}
});
}
Aggregations