Search in sources :

Example 1 with Contour

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);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) ShapeRoi(ij.gui.ShapeRoi) Shape(java.awt.Shape) Contour(imagingbook.pub.regions.Contour) ShapeRoi(ij.gui.ShapeRoi) Roi(ij.gui.Roi)

Example 2 with Contour

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);
        }
    }
}
Also used : Contour(imagingbook.pub.regions.Contour) BinaryRegion(imagingbook.pub.regions.BinaryRegion)

Example 3 with Contour

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;
}
Also used : Contour(imagingbook.pub.regions.Contour) PntInt(imagingbook.pub.geometry.basic.Pnt2d.PntInt)

Example 4 with Contour

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;
}
Also used : Contour(imagingbook.pub.regions.Contour) BinaryRegion(imagingbook.pub.regions.BinaryRegion)

Aggregations

Contour (imagingbook.pub.regions.Contour)4 BinaryRegion (imagingbook.pub.regions.BinaryRegion)2 Roi (ij.gui.Roi)1 ShapeRoi (ij.gui.ShapeRoi)1 PntInt (imagingbook.pub.geometry.basic.Pnt2d.PntInt)1 BasicStroke (java.awt.BasicStroke)1 Shape (java.awt.Shape)1