use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.
the class TestBinaryImageOps method labelToClusters.
@Test
public void labelToClusters() {
FastQueue<Point2D_I32> queue = new FastQueue<>(16, Point2D_I32.class, true);
GrayS32 labels = new GrayS32(4, 4);
labels.data = new int[] { 1, 2, 3, 4, 5, 0, 2, 2, 3, 4, 4, 4, 0, 0, 0, 0 };
List<List<Point2D_I32>> ret = BinaryImageOps.labelToClusters(labels, 5, queue);
assertEquals(5, ret.size());
assertEquals(1, ret.get(0).size());
assertEquals(3, ret.get(1).size());
assertEquals(2, ret.get(2).size());
assertEquals(4, ret.get(3).size());
assertEquals(1, ret.get(4).size());
}
use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.
the class TestContourTracer method checkMarkWhite.
/**
* Make sure it is marking surrounding white pixels
*/
@Test
public void checkMarkWhite() {
String b = "000000\n" + "001100\n" + "000100\n" + "000000\n";
String a = "022220\n" + "021120\n" + "022120\n" + "002220\n";
GrayU8 before = stringToImage(b);
GrayU8 after = stringToImage(a);
GrayS32 label = new GrayS32(before.width, before.height);
ContourTracer alg = new ContourTracer(ConnectRule.EIGHT);
// process the image
alg.setInputs(before, label, queue);
queue.grow();
alg.trace(2, 2, 1, true);
for (int i = 0; i < before.height; i++) {
for (int j = 0; j < before.width; j++) {
if (after.get(j, i) == 2)
assertEquals(255, before.get(j, i));
else
assertEquals(after.get(j, i), before.get(j, i));
}
}
}
use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.
the class TestContourTracer method shiftContourCheck.
/**
* Given a pattern that is only a contour, it sees if it has the expected results when the pattern
* is shifted to every possible location in the image
*/
public void shiftContourCheck(GrayU8 pattern, int expectedSize, ConnectRule rule) {
ContourTracer alg = new ContourTracer(rule);
GrayU8 input = new GrayU8(4, 5);
GrayS32 label = new GrayS32(input.width, input.height);
// exhaustively try all initial locations
for (int y = 0; y < input.height - pattern.height + 1; y++) {
for (int x = 0; x < input.width - pattern.width + 1; x++) {
// paste the pattern in to the larger image
ImageMiscOps.fill(input, 0);
GrayU8 sub = input.subimage(x, y, x + pattern.width, y + pattern.height, null);
sub.setTo(pattern);
// reset other data structures
ImageMiscOps.fill(label, 0);
queue.reset();
queue.grow();
// process the image
alg.setInputs(addBorder(input), label, queue);
alg.trace(2, x + 1, y + 1, true);
// forward then back
assertEquals(expectedSize, queue.sizeOfTail());
// see if the image has been correctly labeled
for (int yy = 0; yy < input.height; yy++) {
for (int xx = 0; xx < input.width; xx++) {
boolean isOne = false;
if (pattern.isInBounds(xx - x, yy - y)) {
isOne = pattern.get(xx - x, yy - y) == 1;
}
if (isOne)
assertEquals(2, label.get(xx, yy));
else
assertEquals(0, label.get(xx, yy));
}
}
}
}
}
use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.
the class TestContourTracer method interior2.
@Test
public void interior2() {
String s = "01111\n" + "01101\n" + "11111\n";
GrayU8 input = stringToImage(s);
GrayS32 label = new GrayS32(input.width, input.height);
ContourTracer alg = new ContourTracer(ConnectRule.FOUR);
// process the image
alg.setInputs(addBorder(input), label, queue);
queue.grow();
alg.trace(2, 3 + 1, 0 + 1, false);
assertEquals(8, queue.sizeOfTail());
}
use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.
the class TestContourTracer method funky3.
@Test
public void funky3() {
String s = "0100\n" + "0110\n" + "1101\n";
GrayU8 input = stringToImage(s);
GrayS32 label = new GrayS32(input.width, input.height);
ContourTracer alg = new ContourTracer(ConnectRule.EIGHT);
// process the image
alg.setInputs(addBorder(input), label, queue);
queue.grow();
alg.trace(2, 1 + 1, 0 + 1, true);
assertEquals(7, queue.totalPoints());
assertEquals(7, queue.sizeOfTail());
}
Aggregations