use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.
the class TestMergeSmallRegions method adjacentBorder4.
@Test
public void adjacentBorder4() {
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.FOUR, 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[] {};
int[] edges4 = new int[] { 0, 9, 11 };
int[] edges12 = new int[] { 10, 11 };
checkNode(alg, edges8, 0);
checkNode(alg, edges4, 1);
checkNode(alg, edges12, 2);
}
use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.
the class TestMergeSmallRegions method findAdjacentRegions_center.
@Test
public void findAdjacentRegions_center() {
int N = 9;
GrayS32 pixelToRegion = new GrayS32(5, 4);
pixelToRegion.data = new int[] { 1, 1, 1, 1, 1, 1, 2, 3, 4, 1, 1, 5, 6, 7, 1, 1, 8, 8, 8, 1 };
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(5, true);
alg.segmentToPruneID.set(2, 0);
alg.segmentToPruneID.set(5, 1);
alg.pruneGraph.grow().init(2);
alg.pruneGraph.grow().init(5);
alg.findAdjacentRegions(pixelToRegion);
// See expected if the graph is constructed
int[] edges2 = new int[] { 1, 3, 5 };
int[] edges5 = new int[] { 1, 2, 6, 8 };
checkNode(alg, edges2, 0);
checkNode(alg, edges5, 1);
}
use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.
the class TestMergeSmallRegions method findAdjacentRegions_bottom.
@Test
public void findAdjacentRegions_bottom() {
int N = 9;
GrayS32 pixelToRegion = new GrayS32(5, 4);
pixelToRegion.data = new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 2, 1, 1, 3, 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(3, true);
alg.segmentPruneFlag.set(5, true);
alg.segmentToPruneID.set(2, 0);
alg.segmentToPruneID.set(3, 1);
alg.segmentToPruneID.set(5, 2);
alg.pruneGraph.grow().init(2);
alg.pruneGraph.grow().init(3);
alg.pruneGraph.grow().init(5);
alg.findAdjacentRegions(pixelToRegion);
// See expected if the graph is constructed
int[] edges2 = new int[] { 1, 4 };
int[] edges3 = new int[] { 1, 5 };
int[] edges5 = new int[] { 1, 3 };
checkNode(alg, edges2, 0);
checkNode(alg, edges3, 1);
checkNode(alg, edges5, 2);
}
use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.
the class TestSegmentMeanShiftSearchColor method compareToGray.
public void compareToGray(boolean fast) {
Planar<GrayF32> image = new Planar<>(GrayF32.class, 20, 25, 1);
GImageMiscOps.fillUniform(image, rand, 0, 256);
ImageType<Planar<GrayF32>> imageType = ImageType.pl(1, GrayF32.class);
InterpolatePixelMB<Planar<GrayF32>> interpMB = FactoryInterpolation.createPixelMB(0, 255, InterpolationType.BILINEAR, BorderType.EXTENDED, imageType);
InterpolatePixelS<GrayF32> interpSB = FactoryInterpolation.bilinearPixelS(GrayF32.class, BorderType.EXTENDED);
SegmentMeanShiftSearchColor<Planar<GrayF32>> algMB = new SegmentMeanShiftSearchColor<>(30, 0.05f, interpMB, 2, 2, 200, fast, imageType);
SegmentMeanShiftSearchGray<GrayF32> algSB = new SegmentMeanShiftSearchGray<>(30, 0.05f, interpSB, 2, 2, 200, fast);
algMB.process(image);
algSB.process(image.getBand(0));
// there should be a fair number of local peaks due to the image being random
assertTrue(algMB.getModeLocation().size > 20);
assertEquals(algMB.getModeColor().size, algSB.getModeColor().size);
assertEquals(algMB.getModeLocation().size, algSB.getModeLocation().size);
assertEquals(algMB.getRegionMemberCount().size, algSB.getRegionMemberCount().size);
for (int i = 0; i < algMB.getModeColor().size; i++) {
assertEquals(algMB.getModeColor().get(i)[0], algSB.getModeColor().get(i)[0], 1e-4f);
assertEquals(algMB.getModeLocation().get(i).x, algSB.getModeLocation().get(i).x, 1e-4f);
assertEquals(algMB.getModeLocation().get(i).y, algSB.getModeLocation().get(i).y, 1e-4f);
assertEquals(algMB.getRegionMemberCount().get(i), algSB.getRegionMemberCount().get(i));
}
GrayS32 segmentMB = algMB.getPixelToRegion();
GrayS32 segmentSB = algSB.getPixelToRegion();
for (int y = 0; y < segmentMB.height; y++) {
for (int x = 0; x < segmentMB.width; x++) {
assertEquals(segmentMB.get(x, y), segmentSB.get(x, y));
}
}
}
use of boofcv.struct.image.GrayS32 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