Search in sources :

Example 46 with GrowQueue_I32

use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.

the class TestMinimizeEnergyPrune method createSquareCorners.

private GrowQueue_I32 createSquareCorners(int x0, int y0, int x1, int y1) {
    GrowQueue_I32 corners = new GrowQueue_I32();
    int c0 = 0;
    int c1 = c0 + x1 - x0;
    int c2 = c1 + y1 - y0;
    int c3 = c2 + x1 - x0;
    corners.add(c0);
    corners.add(c1);
    corners.add(c2);
    corners.add(c3);
    return corners;
}
Also used : GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32)

Example 47 with GrowQueue_I32

use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.

the class TestRefinePolyLineCorner method tooFewPoints.

/**
 * Test to see if it gracefully handles the case where there are too few points
 */
@Test
public void tooFewPoints() {
    RefinePolyLineCorner alg = new RefinePolyLineCorner(true);
    GrowQueue_I32 corners = new GrowQueue_I32();
    List<Point2D_I32> contour = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        assertFalse(alg.fit(contour, corners));
        corners.add(i);
        contour.add(new Point2D_I32(i, 2));
    }
    assertTrue(alg.fit(contour, corners));
}
Also used : ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 48 with GrowQueue_I32

use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.

the class TestMergeSmallRegions method process.

/**
 * Runs everything to remove the small patches. This test hsa been designed to take multiple
 * passes to complete.
 */
@Test
public void process() {
    GrayU8 image = new GrayU8(10, 9);
    image.data = new byte[] { 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 7, 8, 0, 0, 0, 0, 0, 5, 6, 5, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 7, 0, 0, 0, 5, 5, 4, 4, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 0, 0, 0, 0, 0, 0, 9, 9, 6, 7 };
    GrayS32 pixelToRegion = new GrayS32(10, 9);
    pixelToRegion.data = new int[] { 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 4, 5, 0, 0, 0, 0, 0, 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 9, 0, 0, 0, 1, 1, 3, 3, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 6, 6, 7, 8 };
    GrowQueue_I32 memberCount = new GrowQueue_I32();
    memberCount.resize(10);
    for (int i = 0; i < pixelToRegion.data.length; i++) {
        memberCount.data[pixelToRegion.data[i]]++;
    }
    FastQueue<float[]> regionColor = new FastQueue<float[]>(float[].class, true) {

        protected float[] createInstance() {
            return new float[1];
        }
    };
    regionColor.resize(10);
    ComputeRegionMeanColor<GrayU8> mean = new ComputeRegionMeanColor.U8();
    mean.process(image, pixelToRegion, memberCount, regionColor);
    MergeSmallRegions<GrayU8> alg = new MergeSmallRegions<>(3, ConnectRule.FOUR, mean);
    alg.process(image, pixelToRegion, memberCount, regionColor);
    // check the results.  Should only be three regions
    assertEquals(3, memberCount.size);
    assertEquals(3, regionColor.size);
    GrowQueue_I32 memberExpected = new GrowQueue_I32(3);
    memberExpected.resize(3);
    for (int i = 0; i < pixelToRegion.data.length; i++) {
        memberExpected.data[pixelToRegion.data[i]]++;
    }
    for (int i = 0; i < 3; i++) assertEquals(memberExpected.get(i), memberCount.get(i));
    // simple sanity check
    assertTrue(memberExpected.get(0) > memberExpected.get(1));
}
Also used : GrayU8(boofcv.struct.image.GrayU8) FastQueue(org.ddogleg.struct.FastQueue) GrayU8(boofcv.struct.image.GrayU8) GrayS32(boofcv.struct.image.GrayS32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 49 with GrowQueue_I32

use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.

the class TestMergeSmallRegions method setupPruneList.

@Test
public void setupPruneList() {
    GrowQueue_I32 regionMemberCount = new GrowQueue_I32();
    regionMemberCount.size = 6;
    regionMemberCount.data = new int[] { 10, 11, 20, 20, 10, 20 };
    MergeSmallRegions<GrayF32> alg = new MergeSmallRegions(11, ConnectRule.FOUR, null);
    assertTrue(alg.setupPruneList(regionMemberCount));
    assertEquals(2, alg.pruneGraph.size());
    assertEquals(0, alg.pruneGraph.get(0).segment);
    assertEquals(4, alg.pruneGraph.get(1).segment);
    assertEquals(0, alg.pruneGraph.get(0).edges.size);
    assertEquals(0, alg.pruneGraph.get(1).edges.size);
    boolean[] flags = new boolean[] { true, false, false, false, true, false };
    for (int i = 0; i < 6; i++) assertEquals(flags[i], alg.segmentPruneFlag.get(i));
    assertEquals(0, alg.segmentToPruneID.get(0));
    assertEquals(1, alg.segmentToPruneID.get(4));
}
Also used : GrayF32(boofcv.struct.image.GrayF32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 50 with GrowQueue_I32

use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.

the class TestSegmentMeanShiftSearchGray method simpleTest.

/**
 * Process a random image and do a basic sanity check on the output
 */
@Test
public void simpleTest() {
    GrayF32 image = new GrayF32(20, 25);
    ImageMiscOps.fillUniform(image, rand, 0, 256);
    SegmentMeanShiftSearchGray<GrayF32> alg = new SegmentMeanShiftSearchGray<>(30, 0.05f, interp, 2, 2, 100, false);
    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) Point2D_I32(georegression.struct.point.Point2D_I32) GrayS32(boofcv.struct.image.GrayS32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Aggregations

GrowQueue_I32 (org.ddogleg.struct.GrowQueue_I32)60 Test (org.junit.Test)35 Point2D_I32 (georegression.struct.point.Point2D_I32)21 GrayS32 (boofcv.struct.image.GrayS32)10 ArrayList (java.util.ArrayList)7 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)6 Point2D_F64 (georegression.struct.point.Point2D_F64)5 FastQueue (org.ddogleg.struct.FastQueue)5 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)3 ColorQueue_F32 (boofcv.struct.feature.ColorQueue_F32)3 GrayF32 (boofcv.struct.image.GrayF32)3 GrowQueue_I8 (org.ddogleg.struct.GrowQueue_I8)3 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)2 BrightFeature (boofcv.struct.feature.BrightFeature)2 LineGeneral2D_F64 (georegression.struct.line.LineGeneral2D_F64)2 Point3D_F64 (georegression.struct.point.Point3D_F64)2 Se3_F64 (georegression.struct.se.Se3_F64)2 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)2 RectangleLength2D_I32 (georegression.struct.shapes.RectangleLength2D_I32)2 BufferedImage (java.awt.image.BufferedImage)2