Search in sources :

Example 6 with GrayS32

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

the class TestBinaryImageOps method labelToClusters.

@Test
public void labelToClusters() {
    FastQueue<Point2D_I32> queue = new FastQueue<>(16, Point2D_I32.class, true);
    GrayS32 labels = new GrayS32(4, 4);
    labels.data = new int[] { 1, 2, 3, 4, 5, 0, 2, 2, 3, 4, 4, 4, 0, 0, 0, 0 };
    List<List<Point2D_I32>> ret = BinaryImageOps.labelToClusters(labels, 5, queue);
    assertEquals(5, ret.size());
    assertEquals(1, ret.get(0).size());
    assertEquals(3, ret.get(1).size());
    assertEquals(2, ret.get(2).size());
    assertEquals(4, ret.get(3).size());
    assertEquals(1, ret.get(4).size());
}
Also used : FastQueue(org.ddogleg.struct.FastQueue) Point2D_I32(georegression.struct.point.Point2D_I32) List(java.util.List) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 7 with GrayS32

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

the class TestContourTracer method checkMarkWhite.

/**
 * Make sure it is marking surrounding white pixels
 */
@Test
public void checkMarkWhite() {
    String b = "000000\n" + "001100\n" + "000100\n" + "000000\n";
    String a = "022220\n" + "021120\n" + "022120\n" + "002220\n";
    GrayU8 before = stringToImage(b);
    GrayU8 after = stringToImage(a);
    GrayS32 label = new GrayS32(before.width, before.height);
    ContourTracer alg = new ContourTracer(ConnectRule.EIGHT);
    // process the image
    alg.setInputs(before, label, queue);
    queue.grow();
    alg.trace(2, 2, 1, true);
    for (int i = 0; i < before.height; i++) {
        for (int j = 0; j < before.width; j++) {
            if (after.get(j, i) == 2)
                assertEquals(255, before.get(j, i));
            else
                assertEquals(after.get(j, i), before.get(j, i));
        }
    }
}
Also used : GrayU8(boofcv.struct.image.GrayU8) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 8 with GrayS32

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

the class TestContourTracer method shiftContourCheck.

/**
 * Given a pattern that is only a contour, it sees if it has the expected results when the pattern
 * is shifted to every possible location in the image
 */
public void shiftContourCheck(GrayU8 pattern, int expectedSize, ConnectRule rule) {
    ContourTracer alg = new ContourTracer(rule);
    GrayU8 input = new GrayU8(4, 5);
    GrayS32 label = new GrayS32(input.width, input.height);
    // exhaustively try all initial locations
    for (int y = 0; y < input.height - pattern.height + 1; y++) {
        for (int x = 0; x < input.width - pattern.width + 1; x++) {
            // paste the pattern in to the larger image
            ImageMiscOps.fill(input, 0);
            GrayU8 sub = input.subimage(x, y, x + pattern.width, y + pattern.height, null);
            sub.setTo(pattern);
            // reset other data structures
            ImageMiscOps.fill(label, 0);
            queue.reset();
            queue.grow();
            // process the image
            alg.setInputs(addBorder(input), label, queue);
            alg.trace(2, x + 1, y + 1, true);
            // forward then back
            assertEquals(expectedSize, queue.sizeOfTail());
            // see if the image has been correctly labeled
            for (int yy = 0; yy < input.height; yy++) {
                for (int xx = 0; xx < input.width; xx++) {
                    boolean isOne = false;
                    if (pattern.isInBounds(xx - x, yy - y)) {
                        isOne = pattern.get(xx - x, yy - y) == 1;
                    }
                    if (isOne)
                        assertEquals(2, label.get(xx, yy));
                    else
                        assertEquals(0, label.get(xx, yy));
                }
            }
        }
    }
}
Also used : GrayU8(boofcv.struct.image.GrayU8) GrayS32(boofcv.struct.image.GrayS32)

Example 9 with GrayS32

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

the class TestContourTracer method interior2.

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

Example 10 with GrayS32

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

the class TestContourTracer method funky3.

@Test
public void funky3() {
    String s = "0100\n" + "0110\n" + "1101\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, 1 + 1, 0 + 1, true);
    assertEquals(7, queue.totalPoints());
    assertEquals(7, queue.sizeOfTail());
}
Also used : GrayU8(boofcv.struct.image.GrayU8) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

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