Search in sources :

Example 26 with GrayS32

use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.

the class VisualizeWatershedApp method main.

public static void main(String[] args) {
    BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample("segment/berkeley_horses.jpg"));
    GrayU8 gray = new GrayU8(image.getWidth(), image.getHeight());
    ConvertBufferedImage.convertFrom(image, gray);
    WatershedVincentSoille1991 alg = FactorySegmentationAlg.watershed(ConnectRule.FOUR);
    alg.process(gray);
    GrayS32 pixelToRegion = alg.getOutput();
    VisualizeRegions.watersheds(pixelToRegion, image, 0);
    alg.removeWatersheds();
    int numRegions = alg.getTotalRegions();
    BufferedImage outRegions = VisualizeRegions.regions(pixelToRegion, numRegions, null);
    ShowImages.showWindow(image, "Watershed");
    ShowImages.showWindow(outRegions, "Regions");
}
Also used : WatershedVincentSoille1991(boofcv.alg.segmentation.watershed.WatershedVincentSoille1991) GrayU8(boofcv.struct.image.GrayU8) GrayS32(boofcv.struct.image.GrayS32) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 27 with GrayS32

use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.

the class TestClusterLabeledImage method uniform.

/**
 * Uniform image given different values.  Should produce an output image of all zeros.
 */
@Test
public void uniform() {
    GrayS32 input = new GrayS32(5, 7);
    GrayS32 output = new GrayS32(5, 7);
    for (int value = 0; value < 3; value++) {
        GImageMiscOps.fill(input, value);
        for (int i = 0; i < rules.length; i++) {
            GImageMiscOps.fillUniform(output, rand, 0, 1000);
            ClusterLabeledImage alg = new ClusterLabeledImage(rules[i]);
            alg.process(input, output, counts);
            assertEquals(1, counts.size);
            assertEquals(5 * 7, counts.get(0));
            for (int index = 0; index < output.data.length; index++) assertEquals(0, output.data[index]);
        }
    }
}
Also used : GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 28 with GrayS32

use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.

the class TestClusterLabeledImage method case0_connect8.

@Test
public void case0_connect8() {
    GrayS32 input = new GrayS32(5, 5);
    input.data = case0;
    int[] expected = case0;
    GrayS32 output = new GrayS32(5, 5);
    ClusterLabeledImage alg = new ClusterLabeledImage(ConnectRule.EIGHT);
    alg.process(input, output, counts);
    int[] convert = new int[3];
    convert[0] = output.get(0, 0);
    convert[1] = output.get(0, 2);
    convert[2] = output.get(1, 2);
    assertEquals(convert.length, counts.size);
    int sum = 0;
    for (int i = 0; i < counts.size; i++) sum += counts.get(i);
    assertEquals(25, sum);
    for (int j = 0; j < output.data.length; j++) {
        assertEquals(convert[expected[j]], output.data[j]);
    }
}
Also used : GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 29 with GrayS32

use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.

the class TestClusterLabeledImage method sameColorIslands.

/**
 * Same color used on separate islands.  Each island should have its own color on output
 */
@Test
public void sameColorIslands() {
    GrayS32 input = new GrayS32(5, 5);
    input.data = new int[] { 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1 };
    int[] expected = new int[] { 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2 };
    for (int i = 0; i < rules.length; i++) {
        GrayS32 output = new GrayS32(5, 5);
        ClusterLabeledImage alg = new ClusterLabeledImage(rules[i]);
        alg.process(input, output, counts);
        int[] convert = new int[3];
        convert[0] = output.get(0, 0);
        convert[1] = output.get(2, 0);
        convert[2] = output.get(2, 4);
        assertEquals(3, counts.size);
        assertEquals(4, counts.get(convert[0]));
        assertEquals(15, counts.get(convert[1]));
        assertEquals(6, counts.get(convert[2]));
        for (int j = 0; j < output.data.length; j++) {
            assertEquals(convert[expected[j]], output.data[j]);
        }
    }
}
Also used : GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 30 with GrayS32

use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.

the class TestMergeRegionMeanShift method basicAll.

@Test
public void basicAll() {
    MergeRegionMeanShift alg = new MergeRegionMeanShift(1, 1);
    GrayS32 pixelToRegion = new GrayS32(4, 4);
    pixelToRegion.data = new int[] { 0, 0, 0, 1, 2, 0, 0, 1, 2, 0, 1, 1, 0, 0, 3, 1 };
    GrowQueue_I32 regionMemberCount = new GrowQueue_I32();
    regionMemberCount.data = new int[] { 1, 2, 3, 4 };
    regionMemberCount.size = 4;
    FastQueue<float[]> regionColor = createList(5, 1, 6, 4);
    FastQueue<Point2D_I32> modeLocation = new FastQueue<>(Point2D_I32.class, true);
    modeLocation.grow().set(0, 0);
    modeLocation.grow().set(3, 3);
    modeLocation.grow().set(0, 1);
    modeLocation.grow().set(2, 3);
    alg.process(pixelToRegion, regionMemberCount, regionColor, modeLocation);
    GrayS32 expectedP2R = new GrayS32(4, 4);
    expectedP2R.data = new int[] { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 2, 1 };
    int[] expectedCount = new int[] { 4, 2, 4 };
    for (int i = 0; i < expectedP2R.data.length; i++) assertEquals(expectedP2R.data[i], pixelToRegion.data[i]);
    for (int i = 0; i < expectedCount.length; i++) assertEquals(expectedCount[i], regionMemberCount.data[i]);
}
Also used : FastQueue(org.ddogleg.struct.FastQueue) Point2D_I32(georegression.struct.point.Point2D_I32) GrayS32(boofcv.struct.image.GrayS32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Aggregations

GrayS32 (boofcv.struct.image.GrayS32)102 Test (org.junit.Test)79 GrayU8 (boofcv.struct.image.GrayU8)52 GrayF32 (boofcv.struct.image.GrayF32)13 GrowQueue_I32 (org.ddogleg.struct.GrowQueue_I32)10 Point2D_I32 (georegression.struct.point.Point2D_I32)7 FactoryGImageGray (boofcv.core.image.FactoryGImageGray)4 GImageGray (boofcv.core.image.GImageGray)4 ImageGray (boofcv.struct.image.ImageGray)4 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)3 ImageDimension (boofcv.struct.image.ImageDimension)3 BufferedImage (java.awt.image.BufferedImage)3 FastQueue (org.ddogleg.struct.FastQueue)3 WatershedVincentSoille1991 (boofcv.alg.segmentation.watershed.WatershedVincentSoille1991)2 IntegralKernel (boofcv.alg.transform.ii.IntegralKernel)2 ImageBorder_S32 (boofcv.core.image.border.ImageBorder_S32)2 ListDisplayPanel (boofcv.gui.ListDisplayPanel)2 ImageRectangle (boofcv.struct.ImageRectangle)2 PackedSetsPoint2D_I32 (boofcv.struct.PackedSetsPoint2D_I32)2 Kernel2D_S32 (boofcv.struct.convolve.Kernel2D_S32)2