Search in sources :

Example 96 with GrayS32

use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.

the class TestContourTracer method interior1.

@Test
public void interior1() {
    String s = "01110\n" + "01101\n" + "11110\n";
    GrayU8 input = stringToImage(s);
    GrayS32 label = new GrayS32(input.width, input.height);
    ContourTracer alg = new ContourTracer(ConnectRule.EIGHT);
    // process the image
    alg.setInputs(addBorder(input), label, queue);
    queue.grow();
    alg.trace(2, 3 + 1, 0 + 1, false);
    assertEquals(4, queue.sizeOfTail());
}
Also used : GrayU8(boofcv.struct.image.GrayU8) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 97 with GrayS32

use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.

the class TestLinearContourLabelChang2004 method test2_4.

@Test
public void test2_4() {
    GrayU8 input = TEST2.clone();
    GrayS32 labeled = new GrayS32(input.width, input.height);
    LinearContourLabelChang2004 alg = new LinearContourLabelChang2004(ConnectRule.FOUR);
    alg.process(input, labeled);
    assertEquals(14, alg.getContours().size);
    checkContour(alg, labeled, 4);
}
Also used : GrayU8(boofcv.struct.image.GrayU8) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 98 with GrayS32

use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.

the class TestLinearContourLabelChang2004 method test1_4.

@Test
public void test1_4() {
    GrayU8 input = TEST1.clone();
    GrayS32 labeled = new GrayS32(input.width, input.height);
    LinearContourLabelChang2004 alg = new LinearContourLabelChang2004(ConnectRule.FOUR);
    alg.process(input, labeled);
    assertEquals(2, alg.getContours().size);
    checkContour(alg, labeled, 4);
}
Also used : GrayU8(boofcv.struct.image.GrayU8) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 99 with GrayS32

use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.

the class TestLinearContourLabelChang2004 method test3_4.

@Test
public void test3_4() {
    GrayU8 input = TEST4.clone();
    GrayS32 labeled = new GrayS32(input.width, input.height);
    LinearContourLabelChang2004 alg = new LinearContourLabelChang2004(ConnectRule.FOUR);
    alg.process(input, labeled);
    assertEquals(1, alg.getContours().size);
    checkContour(alg, labeled, 4);
}
Also used : GrayU8(boofcv.struct.image.GrayU8) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 100 with GrayS32

use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.

the class TestLinearContourLabelChang2004 method findContour8.

/**
 * Create an unordered list of all points in the internal and external contour
 */
private List<Point2D_I32> findContour8(GrayS32 labeled, int target) {
    List<Point2D_I32> list = new ArrayList<>();
    ImageBorder<GrayS32> border = FactoryImageBorder.singleValue(labeled, 0);
    for (int y = 0; y < labeled.height; y++) {
        for (int x = 0; x < labeled.width; x++) {
            if (target == labeled.get(x, y)) {
                boolean isContour = false;
                for (int i = 0; i < local.size() - 1; i++) {
                    Point2D_I32 a = local.get(i);
                    Point2D_I32 b = local.get(i + 1);
                    if (get(border, x + a.x, y + a.y) != target && get(border, x + b.x, y + b.y) != target) {
                        isContour = true;
                        break;
                    }
                }
                if (!isContour && get(border, x + 1, y) != target)
                    isContour = true;
                if (!isContour && get(border, x - 1, y) != target)
                    isContour = true;
                if (!isContour && get(border, x, y + 1) != target)
                    isContour = true;
                if (!isContour && get(border, x, y - 1) != target)
                    isContour = true;
                if (isContour)
                    list.add(new Point2D_I32(x, y));
            }
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) PackedSetsPoint2D_I32(boofcv.struct.PackedSetsPoint2D_I32) Point2D_I32(georegression.struct.point.Point2D_I32) GrayS32(boofcv.struct.image.GrayS32)

Aggregations

GrayS32 (boofcv.struct.image.GrayS32)102 Test (org.junit.Test)79 GrayU8 (boofcv.struct.image.GrayU8)52 GrayF32 (boofcv.struct.image.GrayF32)13 GrowQueue_I32 (org.ddogleg.struct.GrowQueue_I32)10 Point2D_I32 (georegression.struct.point.Point2D_I32)7 FactoryGImageGray (boofcv.core.image.FactoryGImageGray)4 GImageGray (boofcv.core.image.GImageGray)4 ImageGray (boofcv.struct.image.ImageGray)4 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)3 ImageDimension (boofcv.struct.image.ImageDimension)3 BufferedImage (java.awt.image.BufferedImage)3 FastQueue (org.ddogleg.struct.FastQueue)3 WatershedVincentSoille1991 (boofcv.alg.segmentation.watershed.WatershedVincentSoille1991)2 IntegralKernel (boofcv.alg.transform.ii.IntegralKernel)2 ImageBorder_S32 (boofcv.core.image.border.ImageBorder_S32)2 ListDisplayPanel (boofcv.gui.ListDisplayPanel)2 ImageRectangle (boofcv.struct.ImageRectangle)2 PackedSetsPoint2D_I32 (boofcv.struct.PackedSetsPoint2D_I32)2 Kernel2D_S32 (boofcv.struct.convolve.Kernel2D_S32)2