Search in sources :

Example 1 with ConnectRule

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());
        }
    }
}
Also used : GrayU8(boofcv.struct.image.GrayU8) ConnectRule(boofcv.struct.ConnectRule) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Aggregations

ConnectRule (boofcv.struct.ConnectRule)1 GrayS32 (boofcv.struct.image.GrayS32)1 GrayU8 (boofcv.struct.image.GrayU8)1 Test (org.junit.Test)1