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;
}
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));
}
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));
}
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));
}
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);
}
}
}
Aggregations