use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class GeneralSegmentSlicColorChecks method easyTest.
/**
* Give it an easy image to segment and see how well it does.
*/
@Test
public void easyTest() {
T input = imageType.createImage(30, 40);
GrayS32 output = new GrayS32(30, 40);
GImageMiscOps.fillRectangle(input, 100, 0, 0, 15, 40);
SegmentSlic<T> alg = createAlg(12, 200, 10, ConnectRule.EIGHT);
alg.process(input, output);
GrowQueue_I32 memberCount = alg.getRegionMemberCount();
checkUnique(alg, output, memberCount.size);
// see if the member count is correctly computed
GrowQueue_I32 foundCount = new GrowQueue_I32(memberCount.size);
foundCount.resize(memberCount.size);
ImageSegmentationOps.countRegionPixels(output, foundCount.size, foundCount.data);
for (int i = 0; i < memberCount.size; i++) {
assertEquals(memberCount.get(i), foundCount.get(i));
}
}
use of org.ddogleg.struct.GrowQueue_I32 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]);
}
}
use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class TestComputeRegionMeanColor method before.
@Before
public void before() {
segments = new GrayS32(w, h);
segments.data = new int[] { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
regionMemberCount = new GrowQueue_I32();
for (int i = 0; i < 4; i++) regionMemberCount.add(5);
}
use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class DetectPolylineApp method detectorProcess.
@Override
protected void detectorProcess(ImageGray input, GrayU8 binary) {
// System.out.println("processing image "+count++);
binaryToContour.process(binary, labeled);
contours = BinaryImageOps.convertContours(binaryToContour);
int minContourPixels = minimumContourSize.computeI(Math.min(input.width, input.height));
polylines.clear();
GrowQueue_I32 indices = new GrowQueue_I32();
for (int i = 0; i < contours.size(); i++) {
List<Point2D_I32> contour = contours.get(i).external;
if (contour.size() < minContourPixels)
continue;
if (contourToPolyline.process(contour, indices)) {
List<Point2D_I32> l = new ArrayList<>();
for (int j = 0; j < indices.size; j++) {
l.add(contour.get(indices.get(j)));
}
polylines.add(l);
}
}
}
use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class SplitMergeLineFitSegment method mergeSegments.
/**
* Merges lines together which have an acute angle less than the threshold.
* @return true the list being changed
*/
protected boolean mergeSegments() {
// can't merge a single line
if (splits.size <= 2)
return false;
boolean change = false;
work.reset();
// first point is always at the start
work.add(splits.data[0]);
for (int i = 0; i < splits.size - 2; i++) {
if (selectSplitBetween(splits.data[i], splits.data[i + 2]) < 0) {
// merge the two lines by not adding it
change = true;
} else {
work.add(splits.data[i + 1]);
}
}
// and end
work.add(splits.data[splits.size - 1]);
// swap the two lists
GrowQueue_I32 tmp = work;
work = splits;
splits = tmp;
return change;
}
Aggregations