use of imagingbook.pub.regions.Contour in project imagingbook-common by imagingbook.
the class ContourOverlay method addContours.
public void addContours(List<? extends Contour> contours, Color color, double strokeWidth) {
BasicStroke stroke = new BasicStroke((float) strokeWidth);
for (Contour c : contours) {
Shape s = c.getPolygonPath();
Roi roi = new ShapeRoi(s);
roi.setStrokeColor(color);
roi.setStroke(stroke);
// roi.setStrokeWidth(strokeWidth);
add(roi);
}
}
use of imagingbook.pub.regions.Contour in project imagingbook-common by imagingbook.
the class RegionContourSegmentation method attachOuterContours.
// ------------------------------------------------------------------------------
private void attachOuterContours() {
for (Contour.Outer c : outerContours) {
int label = c.getLabel();
BinaryRegion reg = getRegion(label);
if (reg == null) {
IJ.log("Error: Could not associate outer contour with label " + label);
} else {
reg.setOuterContour(c);
}
}
}
use of imagingbook.pub.regions.Contour in project imagingbook-common by imagingbook.
the class RegionContourSegmentation method applySegmentation.
@Override
protected boolean applySegmentation() {
for (int v = 0; v < height; v++) {
// scan top to bottom, left to right
// reset label, scan through horiz. line:
int label = 0;
for (int u = 0; u < width; u++) {
if (ip.getPixel(u, v) > 0) {
// hit an unlabeled FOREGROUND pixel
if (label != 0) {
// keep using the same label
setLabel(u, v, label);
} else {
// label == 0
label = getLabel(u, v);
if (label == 0) {
// new (unlabeled) region is hit
// assign a new region label
label = getNextLabel();
PntInt xs = PntInt.from(u, v);
int ds = 0;
Contour.Outer c = traceContour(xs, ds, new Contour.Outer(label));
outerContours.add(c);
setLabel(u, v, label);
}
}
} else {
// hit a BACKGROUND pixel
if (label != 0) {
// exiting a region
if (getLabel(u, v) == BACKGROUND) {
// unlabeled - new inner contour
PntInt xs = PntInt.from(u - 1, v);
int ds = (NT == N4) ? 2 : 1;
Contour.Inner c = traceContour(xs, ds, new Contour.Inner(label));
innerContours.add(c);
}
label = 0;
}
}
}
}
return true;
}
use of imagingbook.pub.regions.Contour in project imagingbook-common by imagingbook.
the class RegionContourSegmentationTest method findFirstRegionWithHole.
private static int findFirstRegionWithHole(List<BinaryRegion> regions) {
int i = 0;
for (BinaryRegion r : regions) {
List<Contour> ics = r.getInnerContours();
if (ics != null && !ics.isEmpty()) {
return i;
}
i = i + 1;
}
return -1;
}
Aggregations