Search in sources :

Example 46 with GrayS32

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

the class TestImageSegmentationOps method markRegionBorders2.

@Test
public void markRegionBorders2() {
    GrayS32 input = new GrayS32(4, 5);
    input.data = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 };
    GrayU8 expected = new GrayU8(4, 5);
    expected.data = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1 };
    GrayU8 found = new GrayU8(4, 5);
    ImageSegmentationOps.markRegionBorders(input, found);
    BoofTesting.assertEquals(expected, found, 1e-4);
}
Also used : GrayU8(boofcv.struct.image.GrayU8) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 47 with GrayS32

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

the class TestSegmentFelzenszwalbHuttenlocher04 method find.

@Test
public void find() {
    SegmentFelzenszwalbHuttenlocher04 alg = new SegmentFelzenszwalbHuttenlocher04(300, 20, null);
    alg.graph = new GrayS32(4, 5);
    alg.graph.data = new int[] { 2, 0, 2, 5, 3, 5, 4, 6, 2, 2, 2, 1, 15, 15, 15, 15, 15, 15, 15, 15 };
    assertEquals(2, alg.find(11));
    assertEquals(2, alg.graph.data[11]);
    assertEquals(0, alg.graph.data[1]);
    assertEquals(2, alg.find(2));
}
Also used : GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 48 with GrayS32

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

the class TestSegmentFelzenszwalbHuttenlocher04 method computeOutput.

@Test
public void computeOutput() {
    SegmentFelzenszwalbHuttenlocher04 alg = new SegmentFelzenszwalbHuttenlocher04(300, 20, null);
    alg.graph = new GrayS32(4, 5);
    alg.graph.data = new int[] { 2, 0, 2, 5, 3, 5, 4, 6, 2, 2, 2, 1, 15, 15, 15, 15, 15, 15, 15, 15 };
    for (int i = 0; i < alg.graph.data.length; i++) alg.regionSize.add(i + 1);
    alg.computeOutput();
    GrowQueue_I32 regionId = alg.getRegionId();
    assertEquals(3, regionId.size);
    assertEquals(2, regionId.get(0));
    assertEquals(5, regionId.get(1));
    assertEquals(15, regionId.get(2));
    GrowQueue_I32 outputRegionSize = alg.getRegionSizes();
    assertEquals(3, outputRegionSize.size);
    assertEquals(3, outputRegionSize.get(0));
    assertEquals(6, outputRegionSize.get(1));
    assertEquals(16, outputRegionSize.get(2));
    GrayS32 expected = new GrayS32(4, 5);
    expected.data = new int[] { 2, 2, 2, 5, 5, 5, 5, 5, 2, 2, 2, 2, 15, 15, 15, 15, 15, 15, 15, 15 };
    BoofTesting.assertEquals(expected, alg.graph, 1e-4);
}
Also used : GrayS32(boofcv.struct.image.GrayS32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 49 with GrayS32

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

the class TestSegmentFelzenszwalbHuttenlocher04 method process.

/**
 * Test it on a trivial segmentation problem
 */
@Test
public void process() {
    GrayU8 image = new GrayU8(20, 25);
    ImageMiscOps.fillRectangle(image, 100, 0, 0, 10, 25);
    GrayS32 output = new GrayS32(20, 25);
    // normal images
    process(image, output);
    // sub-images
    process(BoofTesting.createSubImageOf(image), output);
}
Also used : GrayU8(boofcv.struct.image.GrayU8) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 50 with GrayS32

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

the class TestSegmentFelzenszwalbHuttenlocher04 method mergeSmallRegions.

@Test
public void mergeSmallRegions() {
    SegmentFelzenszwalbHuttenlocher04 alg = new SegmentFelzenszwalbHuttenlocher04(0, 10, null);
    alg.regionSize.resize(20);
    alg.regionSize.set(2, 10);
    alg.regionSize.set(5, 20);
    alg.regionSize.set(15, 9);
    // regions: 2,5,15
    alg.graph = new GrayS32(4, 5);
    alg.graph.data = new int[] { 2, 0, 2, 5, 3, 5, 4, 6, 2, 2, 2, 1, 15, 15, 15, 15, 15, 15, 15, 15 };
    alg.edgesNotMatched.add(new SegmentFelzenszwalbHuttenlocher04.Edge(1, 5));
    alg.edgesNotMatched.add(new SegmentFelzenszwalbHuttenlocher04.Edge(12, 8));
    alg.mergeSmallRegions();
    // see if the regions were merged
    assertEquals(15, alg.find(15));
    assertEquals(15, alg.find(2));
    assertEquals(5, alg.find(5));
}
Also used : 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