use of boofcv.struct.ConnectRule in project BoofCV by lessthanoptimal.
the class GeneralImageSuperpixelsChecks method connectivity.
/**
* Makes sure all pixels with the same label are connected
*/
@Test
public void connectivity() {
for (ImageType<T> t : imageTypes) {
// System.out.println("Image type "+t);
ImageSuperpixels<T> alg = createAlg(t);
T input = t.createImage(width, height);
GrayS32 output = new GrayS32(width, height);
GImageMiscOps.fillUniform(input, rand, 0, 100);
alg.segment(input, output);
assertTrue(alg.getTotalSuperpixels() > 4);
GrayU8 binary = new GrayU8(width, height);
boolean[] selected = new boolean[alg.getTotalSuperpixels()];
for (int i = 0; i < alg.getTotalSuperpixels(); i++) {
selected[i] = true;
BinaryImageOps.labelToBinary(output, binary, selected);
selected[i] = false;
// the number of blobs should always be one
ConnectRule rule = alg.getRule();
assertEquals(1, BinaryImageOps.contour(binary, rule, null).size());
}
}
}
Aggregations