Search in sources :

Example 1 with ColorQueue_F32

use of boofcv.struct.feature.ColorQueue_F32 in project BoofCV by lessthanoptimal.

the class ExampleSegmentSuperpixels method visualize.

/**
 * Visualizes results three ways.  1) Colorized segmented image where each region is given a random color.
 * 2) Each pixel is assigned the mean color through out the region. 3) Black pixels represent the border
 * between regions.
 */
public static <T extends ImageBase<T>> void visualize(GrayS32 pixelToRegion, T color, int numSegments) {
    // Computes the mean color inside each region
    ImageType<T> type = color.getImageType();
    ComputeRegionMeanColor<T> colorize = FactorySegmentationAlg.regionMeanColor(type);
    FastQueue<float[]> segmentColor = new ColorQueue_F32(type.getNumBands());
    segmentColor.resize(numSegments);
    GrowQueue_I32 regionMemberCount = new GrowQueue_I32();
    regionMemberCount.resize(numSegments);
    ImageSegmentationOps.countRegionPixels(pixelToRegion, numSegments, regionMemberCount.data);
    colorize.process(color, pixelToRegion, regionMemberCount, segmentColor);
    // Draw each region using their average color
    BufferedImage outColor = VisualizeRegions.regionsColor(pixelToRegion, segmentColor, null);
    // Draw each region by assigning it a random color
    BufferedImage outSegments = VisualizeRegions.regions(pixelToRegion, numSegments, null);
    // Make region edges appear red
    BufferedImage outBorder = new BufferedImage(color.width, color.height, BufferedImage.TYPE_INT_RGB);
    ConvertBufferedImage.convertTo(color, outBorder, true);
    VisualizeRegions.regionBorders(pixelToRegion, 0xFF0000, outBorder);
    // Show the visualization results
    ListDisplayPanel gui = new ListDisplayPanel();
    gui.addImage(outColor, "Color of Segments");
    gui.addImage(outBorder, "Region Borders");
    gui.addImage(outSegments, "Regions");
    ShowImages.showWindow(gui, "Superpixels", true);
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) ColorQueue_F32(boofcv.struct.feature.ColorQueue_F32) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32)

Example 2 with ColorQueue_F32

use of boofcv.struct.feature.ColorQueue_F32 in project BoofCV by lessthanoptimal.

the class VisualizeImageSegmentationApp method performSegmentation.

private void performSegmentation() {
    long before = System.currentTimeMillis();
    alg.segment(color, pixelToRegion);
    long after = System.currentTimeMillis();
    System.out.println("Total time " + (after - before));
    int numSegments = alg.getTotalSuperpixels();
    // Computes the mean color inside each region
    ImageType<T> type = color.getImageType();
    ComputeRegionMeanColor<T> colorize = FactorySegmentationAlg.regionMeanColor(type);
    FastQueue<float[]> segmentColor = new ColorQueue_F32(type.getNumBands());
    segmentColor.resize(numSegments);
    GrowQueue_I32 regionMemberCount = new GrowQueue_I32();
    regionMemberCount.resize(numSegments);
    ImageSegmentationOps.countRegionPixels(pixelToRegion, numSegments, regionMemberCount.data);
    colorize.process(color, pixelToRegion, regionMemberCount, segmentColor);
    VisualizeRegions.regionsColor(pixelToRegion, segmentColor, outColor);
    VisualizeRegions.regions(pixelToRegion, segmentColor.size(), outSegments);
    // Make edges appear black
    ConvertBufferedImage.convertTo(color, outBorder, true);
    VisualizeRegions.regionBorders(pixelToRegion, 0x000000, outBorder);
}
Also used : ColorQueue_F32(boofcv.struct.feature.ColorQueue_F32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32)

Example 3 with ColorQueue_F32

use of boofcv.struct.feature.ColorQueue_F32 in project BoofCV by lessthanoptimal.

the class TestSegmentSlic method assignLabelsToPixels.

@Test
public void assignLabelsToPixels() {
    DummySlic alg = new DummySlic(4, 1, 10);
    SegmentSlic.Cluster c0 = alg.clusters.grow();
    SegmentSlic.Cluster c1 = alg.clusters.grow();
    SegmentSlic.Cluster c2 = alg.clusters.grow();
    c0.id = 0;
    c1.id = 1;
    c2.id = 2;
    alg.pixels.resize(6);
    alg.pixels.get(0).add(c0, 2);
    alg.pixels.get(0).add(c1, 4);
    alg.pixels.get(0).add(c2, 0.1f);
    alg.pixels.get(1).add(c1, 1);
    alg.pixels.get(1).add(c0, 2);
    for (int i = 2; i < 6; i++) {
        alg.pixels.get(i).add(c1, 0);
        alg.pixels.get(i).add(c2, 0.2f);
    }
    GrayS32 image = new GrayS32(2, 3);
    GrowQueue_I32 regionMemberCount = new GrowQueue_I32();
    FastQueue<float[]> regionColor = new ColorQueue_F32(1);
    alg.assignLabelsToPixels(image, regionMemberCount, regionColor);
    assertEquals(3, regionMemberCount.size);
    assertEquals(3, regionColor.size);
    assertEquals(0, regionMemberCount.get(0));
    assertEquals(5, regionMemberCount.get(1));
    assertEquals(1, regionMemberCount.get(2));
    assertEquals(2, image.get(0, 0));
    assertEquals(1, image.get(1, 0));
    for (int i = 2; i < 6; i++) {
        assertEquals(1, image.data[i]);
    }
}
Also used : ColorQueue_F32(boofcv.struct.feature.ColorQueue_F32) GrayS32(boofcv.struct.image.GrayS32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Aggregations

ColorQueue_F32 (boofcv.struct.feature.ColorQueue_F32)3 GrowQueue_I32 (org.ddogleg.struct.GrowQueue_I32)3 ListDisplayPanel (boofcv.gui.ListDisplayPanel)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 GrayS32 (boofcv.struct.image.GrayS32)1 BufferedImage (java.awt.image.BufferedImage)1 Test (org.junit.Test)1