Search in sources :

Example 31 with GrayS32

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

the class TestMergeSmallRegions method adjacentBorder8.

@Test
public void adjacentBorder8() {
    int N = 13;
    GrayS32 pixelToRegion = new GrayS32(5, 4);
    pixelToRegion.data = new int[] { 0, 0, 0, 0, 0, 8, 2, 0, 9, 4, 7, 1, 3, 5, 11, 0, 0, 6, 10, 12 };
    MergeSmallRegions<GrayF32> alg = new MergeSmallRegions(10, ConnectRule.EIGHT, null);
    alg.initializeMerge(N);
    alg.segmentPruneFlag.resize(N);
    alg.pruneGraph.reset();
    alg.segmentToPruneID.resize(N);
    alg.segmentPruneFlag.set(8, true);
    alg.segmentPruneFlag.set(4, true);
    alg.segmentPruneFlag.set(12, true);
    alg.segmentToPruneID.set(8, 0);
    alg.segmentToPruneID.set(4, 1);
    alg.segmentToPruneID.set(12, 2);
    alg.pruneGraph.grow().init(8);
    alg.pruneGraph.grow().init(4);
    alg.pruneGraph.grow().init(12);
    alg.adjacentBorder(pixelToRegion);
    // See expected if the graph is constructed
    int[] edges8 = new int[] { 0, 2, 1, 7 };
    int[] edges4 = new int[] { 0, 9, 11, 5 };
    int[] edges12 = new int[] { 5, 10, 11 };
    checkNode(alg, edges8, 0);
    checkNode(alg, edges4, 1);
    checkNode(alg, edges12, 2);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 32 with GrayS32

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

the class TestMergeSmallRegions method adjacentInner8.

@Test
public void adjacentInner8() {
    int N = 13;
    GrayS32 pixelToRegion = new GrayS32(5, 4);
    pixelToRegion.data = new int[] { 1, 2, 3, 10, 0, 8, 9, 4, 11, 0, 7, 6, 5, 12, 0, 0, 0, 0, 0, 0 };
    MergeSmallRegions<GrayF32> alg = new MergeSmallRegions(10, ConnectRule.EIGHT, null);
    alg.initializeMerge(N);
    alg.segmentPruneFlag.resize(N);
    alg.pruneGraph.reset();
    alg.segmentToPruneID.resize(N);
    alg.segmentPruneFlag.set(1, true);
    alg.segmentPruneFlag.set(2, true);
    alg.segmentPruneFlag.set(4, true);
    alg.segmentToPruneID.set(1, 0);
    alg.segmentToPruneID.set(2, 1);
    alg.segmentToPruneID.set(4, 2);
    alg.pruneGraph.grow().init(1);
    alg.pruneGraph.grow().init(2);
    alg.pruneGraph.grow().init(4);
    alg.adjacentInner8(pixelToRegion);
    // See expected if the graph is constructed
    int[] edges1 = new int[] {};
    int[] edges2 = new int[] { 3, 4, 9, 8 };
    int[] edges4 = new int[] { 2, 3, 10, 11, 12, 5, 6, 9 };
    checkNode(alg, edges1, 0);
    checkNode(alg, edges2, 1);
    checkNode(alg, edges4, 2);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 33 with GrayS32

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

the class TestMergeSmallRegions method findAdjacentRegions_right.

@Test
public void findAdjacentRegions_right() {
    int N = 9;
    GrayS32 pixelToRegion = new GrayS32(5, 4);
    pixelToRegion.data = new int[] { 1, 1, 1, 1, 2, 1, 1, 1, 1, 3, 1, 1, 1, 7, 4, 1, 1, 1, 1, 5 };
    MergeSmallRegions<GrayF32> alg = new MergeSmallRegions(10, ConnectRule.FOUR, null);
    alg.initializeMerge(N);
    alg.segmentPruneFlag.resize(N);
    alg.pruneGraph.reset();
    alg.segmentToPruneID.resize(N);
    alg.segmentPruneFlag.set(2, true);
    alg.segmentPruneFlag.set(4, true);
    alg.segmentPruneFlag.set(5, true);
    alg.segmentToPruneID.set(2, 0);
    alg.segmentToPruneID.set(4, 1);
    alg.segmentToPruneID.set(5, 2);
    alg.pruneGraph.grow().init(2);
    alg.pruneGraph.grow().init(4);
    alg.pruneGraph.grow().init(5);
    alg.findAdjacentRegions(pixelToRegion);
    // See expected if the graph is constructed
    int[] edges2 = new int[] { 1, 3 };
    int[] edges4 = new int[] { 3, 5, 7 };
    int[] edges5 = new int[] { 1, 4 };
    checkNode(alg, edges2, 0);
    checkNode(alg, edges4, 1);
    checkNode(alg, edges5, 2);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 34 with GrayS32

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

the class TestMergeSmallRegions method adjacentInner4.

/**
 * Make sure a connect-4 rule is correctly enforced
 */
@Test
public void adjacentInner4() {
    int N = 9;
    GrayS32 pixelToRegion = new GrayS32(5, 4);
    pixelToRegion.data = new int[] { 1, 2, 3, 0, 0, 8, 9, 4, 0, 0, 7, 6, 5, 0, 0, 0, 0, 0, 0, 0 };
    MergeSmallRegions<GrayF32> alg = new MergeSmallRegions(10, ConnectRule.FOUR, null);
    alg.initializeMerge(N);
    alg.segmentPruneFlag.resize(N);
    alg.pruneGraph.reset();
    alg.segmentToPruneID.resize(N + 1);
    alg.segmentPruneFlag.set(1, true);
    alg.segmentPruneFlag.set(9, true);
    alg.segmentToPruneID.set(1, 0);
    alg.segmentToPruneID.set(9, 1);
    alg.pruneGraph.grow().init(1);
    alg.pruneGraph.grow().init(9);
    alg.adjacentInner4(pixelToRegion);
    // See expected if the graph is constructed
    int[] edges1 = new int[] { 2, 8 };
    int[] edges9 = new int[] { 2, 4, 6, 8 };
    checkNode(alg, edges1, 0);
    checkNode(alg, edges9, 1);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 35 with GrayS32

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

the class TestSegmentMeanShiftSearchColor method simpleTest.

/**
 * Process a random image and do a basic sanity check on the output
 */
@Test
public void simpleTest() {
    Planar<GrayF32> image = new Planar<>(GrayF32.class, 20, 25, 2);
    GImageMiscOps.fillUniform(image, rand, 0, 256);
    SegmentMeanShiftSearchColor<Planar<GrayF32>> alg = new SegmentMeanShiftSearchColor<>(30, 0.05f, interp, 2, 2, 200, false, imageType);
    alg.process(image);
    FastQueue<Point2D_I32> locations = alg.getModeLocation();
    GrowQueue_I32 counts = alg.getRegionMemberCount();
    GrayS32 peaks = alg.getPixelToRegion();
    FastQueue<float[]> values = alg.getModeColor();
    // there should be a fair number of local peaks due to the image being random
    assertTrue(locations.size > 20);
    // all the lists should be the same size
    assertEquals(locations.size, counts.size);
    assertEquals(locations.size, values.size);
    // total members should equal the number of pixels
    int totalMembers = 0;
    for (int i = 0; i < counts.size; i++) {
        totalMembers += counts.get(i);
    }
    assertEquals(20 * 25, totalMembers);
    // see if the peak to index image is set up correctly and that all the peaks make sense
    for (int y = 0; y < peaks.height; y++) {
        for (int x = 0; x < peaks.width; x++) {
            int peak = peaks.get(x, y);
            // can't test the value because its floating point location which is interpolated using the kernel
            // and the location is lost
            // assertEquals(x+" "+y,computeValue(peakX,peakY,image),value,50);
            assertTrue(counts.get(peak) > 0);
        }
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) Point2D_I32(georegression.struct.point.Point2D_I32) GrayS32(boofcv.struct.image.GrayS32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) 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