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);
}
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);
}
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]);
}
}
Aggregations