use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class SplitMergeLineFitLoop method splitSegments.
/**
* Splits a line in two if there is a point that is too far away
* @return true for change
*/
protected boolean splitSegments() {
boolean change = false;
work.reset();
for (int i = 0; i < splits.size - 1; i++) {
change |= checkSplit(change, i, i + 1);
}
change |= checkSplit(change, splits.size - 1, 0);
// swap the two lists
GrowQueue_I32 tmp = work;
work = splits;
splits = tmp;
return change;
}
use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class SplitMergeLineFitSegment method splitSegments.
/**
* Splits a line in two if there is a paint that is too far away
* @return true for change
*/
protected boolean splitSegments() {
boolean change = false;
work.reset();
for (int i = 0; i < splits.size - 1; i++) {
int start = splits.data[i];
int end = splits.data[i + 1];
int bestIndex = selectSplitBetween(start, end);
if (bestIndex >= 0) {
change |= true;
work.add(start);
work.add(bestIndex);
} else {
work.add(start);
}
}
work.add(splits.data[splits.size - 1]);
// swap the two lists
GrowQueue_I32 tmp = work;
work = splits;
splits = tmp;
return change;
}
use of org.ddogleg.struct.GrowQueue_I32 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 org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class ExampleMultiviewSceneReconstruction method initialize.
/**
* Initialize the 3D world given these two images. imageA is assumed to be the origin of the world.
*/
private void initialize(int imageA, int imageB) {
System.out.println("Initializing 3D world using " + imageA + " and " + imageB);
// Compute the 3D pose and find valid image features
Se3_F64 motionAtoB = new Se3_F64();
List<AssociatedIndex> inliers = new ArrayList<>();
if (!estimateStereoPose(imageA, imageB, motionAtoB, inliers))
throw new RuntimeException("The first image pair is a bad keyframe!");
motionWorldToCamera[imageB].set(motionAtoB);
estimatedImage[imageB] = true;
processedImage[imageB] = true;
// create tracks for only those features in the inlier list
FastQueue<Point2D_F64> pixelsA = imagePixels.get(imageA);
FastQueue<Point2D_F64> pixelsB = imagePixels.get(imageB);
List<Feature3D> tracksA = imageFeature3D.get(imageA);
List<Feature3D> tracksB = imageFeature3D.get(imageB);
GrowQueue_I32 colorsA = imageColors.get(imageA);
for (int i = 0; i < inliers.size(); i++) {
AssociatedIndex a = inliers.get(i);
Feature3D t = new Feature3D();
t.color = colorsA.get(a.src);
t.obs.grow().set(pixelsA.get(a.src));
t.obs.grow().set(pixelsB.get(a.dst));
t.frame.add(imageA);
t.frame.add(imageB);
// compute the 3D coordinate of the feature
Point2D_F64 pa = pixelsA.get(a.src);
Point2D_F64 pb = pixelsB.get(a.dst);
if (!triangulate.triangulate(pa, pb, motionAtoB, t.worldPt))
continue;
// the feature has to be in front of the camera
if (t.worldPt.z > 0) {
featuresAll.add(t);
tracksA.add(t);
tracksB.add(t);
}
}
// adjust the scale so that it's not excessively large or small
normalizeScale(motionWorldToCamera[imageB], tracksA);
}
use of org.ddogleg.struct.GrowQueue_I32 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);
}
Aggregations