Search in sources :

Example 71 with GrayS32

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

the class GeneralSegmentSlicColorChecks method easyTest.

/**
 * Give it an easy image to segment and see how well it does.
 */
@Test
public void easyTest() {
    T input = imageType.createImage(30, 40);
    GrayS32 output = new GrayS32(30, 40);
    GImageMiscOps.fillRectangle(input, 100, 0, 0, 15, 40);
    SegmentSlic<T> alg = createAlg(12, 200, 10, ConnectRule.EIGHT);
    alg.process(input, output);
    GrowQueue_I32 memberCount = alg.getRegionMemberCount();
    checkUnique(alg, output, memberCount.size);
    // see if the member count is correctly computed
    GrowQueue_I32 foundCount = new GrowQueue_I32(memberCount.size);
    foundCount.resize(memberCount.size);
    ImageSegmentationOps.countRegionPixels(output, foundCount.size, foundCount.data);
    for (int i = 0; i < memberCount.size; i++) {
        assertEquals(memberCount.get(i), foundCount.get(i));
    }
}
Also used : GrayS32(boofcv.struct.image.GrayS32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 72 with GrayS32

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

the class TestSegmentSlic method assignLabelsToPixels.

@Test
public void assignLabelsToPixels() {
    DummySlic alg = new DummySlic(4, 1, 10);
    SegmentSlic.Cluster c0 = alg.clusters.grow();
    SegmentSlic.Cluster c1 = alg.clusters.grow();
    SegmentSlic.Cluster c2 = alg.clusters.grow();
    c0.id = 0;
    c1.id = 1;
    c2.id = 2;
    alg.pixels.resize(6);
    alg.pixels.get(0).add(c0, 2);
    alg.pixels.get(0).add(c1, 4);
    alg.pixels.get(0).add(c2, 0.1f);
    alg.pixels.get(1).add(c1, 1);
    alg.pixels.get(1).add(c0, 2);
    for (int i = 2; i < 6; i++) {
        alg.pixels.get(i).add(c1, 0);
        alg.pixels.get(i).add(c2, 0.2f);
    }
    GrayS32 image = new GrayS32(2, 3);
    GrowQueue_I32 regionMemberCount = new GrowQueue_I32();
    FastQueue<float[]> regionColor = new ColorQueue_F32(1);
    alg.assignLabelsToPixels(image, regionMemberCount, regionColor);
    assertEquals(3, regionMemberCount.size);
    assertEquals(3, regionColor.size);
    assertEquals(0, regionMemberCount.get(0));
    assertEquals(5, regionMemberCount.get(1));
    assertEquals(1, regionMemberCount.get(2));
    assertEquals(2, image.get(0, 0));
    assertEquals(1, image.get(1, 0));
    for (int i = 2; i < 6; i++) {
        assertEquals(1, image.data[i]);
    }
}
Also used : ColorQueue_F32(boofcv.struct.feature.ColorQueue_F32) GrayS32(boofcv.struct.image.GrayS32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 73 with GrayS32

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

the class TestRemoveWatersheds method basic.

/**
 * Simple case.  Still will require multiple passes for all the pixels to be assigned.
 */
@Test
public void basic() {
    GrayS32 segmented = new GrayS32(5, 7);
    segmented.data = new int[] { -1, -1, -1, -1, -1, -1, 1, 1, 1, -1, -1, 1, 0, 0, -1, -1, 2, 2, 2, -1, -1, 0, 0, 0, -1, -1, 0, 0, 0, -1, -1, -1, -1, -1, -1 };
    // technically it could be assigned other values and still be a valid solution
    // this expected image is created knowing the exact internal algorithm
    GrayS32 expected = new GrayS32(5, 7);
    expected.data = new int[] { -1, -1, -1, -1, -1, -1, 0, 0, 0, -1, -1, 0, 0, 0, -1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1, -1, -1, -1, -1, -1 };
    RemoveWatersheds alg = new RemoveWatersheds();
    alg.remove(segmented);
    BoofTesting.assertEquals(expected, segmented, 0);
}
Also used : GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 74 with GrayS32

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

the class TestWatershedVincentSoille1991 method sortPixels.

@Test
public void sortPixels() {
    WatershedVincentSoille1991 alg = new Dummy();
    GrayU8 image = new GrayU8(3, 4);
    image.data = new byte[] { 1, 2, 3, 2, 2, 2, 5, 6, 1, 3, 3, (byte) 255 };
    alg.output = new GrayS32(4, 5);
    alg.sortPixels(image);
    assertEquals(0, alg.histogram[0].size);
    assertEquals(2, alg.histogram[1].size);
    assertEquals(4, alg.histogram[2].size);
    assertEquals(3, alg.histogram[3].size);
    assertEquals(0, alg.histogram[4].size);
    assertEquals(1, alg.histogram[5].size);
    assertEquals(1, alg.histogram[6].size);
    for (int i = 7; i < 255; i++) assertEquals(0, alg.histogram[i].size);
    assertEquals(1, alg.histogram[255].size);
    // check output coordinate for (0,2)
    int indexOut = 3 * 4 + 1;
    assertEquals(indexOut, alg.histogram[5].get(0));
}
Also used : GrayU8(boofcv.struct.image.GrayU8) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 75 with GrayS32

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

the class TestWatershedVincentSoille1991_Connect4 method example4.

@Test
public void example4() {
    GrayU8 image = new GrayU8(5, 4);
    image.data = new byte[] { 5, 5, 5, 5, 5, 5, 1, 4, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5 };
    WatershedVincentSoille1991 alg = new WatershedVincentSoille1991.Connect4();
    alg.process(image);
    GrayS32 found = alg.getOutput();
    // found.print();
    assertEquals(4, alg.getTotalRegions());
    int[] expected = new int[] { 1, 1, 0, 2, 2, 1, 1, 0, 2, 2, 1, 1, 0, 0, 0, 0, 0, 3, 3, 3 };
    int index = 0;
    for (int y = 0; y < image.height; y++) {
        for (int x = 0; x < image.width; x++) {
            assertEquals(expected[index++], found.get(x, y));
        }
    }
}
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