use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.
the class TestRecognitionVocabularyTreeNister2006 method describe.
@Test
void describe() {
HierarchicalVocabularyTree<Point2D_F64> tree = create2x2Tree();
// Add a few features at the leaves
List<Point2D_F64> imageFeatures = new ArrayList<>();
for (int i = 0; i < 3; i++) {
imageFeatures.add(new Point2D_F64(-5, -1));
imageFeatures.add(new Point2D_F64(5, -1));
}
// TF-IDF descriptor
var descWeights = new DogArray_F32();
var descWords = new DogArray_I32();
var alg = new RecognitionVocabularyTreeNister2006<Point2D_F64>();
alg.initializeTree(tree);
alg.describe(imageFeatures, descWeights, descWords);
// See if the description is as expected
assertEquals(4, descWeights.size());
assertEquals(4, descWords.size());
// All the expected nodes should have values
float f1 = descWeights.get(descWords.indexOf(1));
float f2 = descWeights.get(descWords.indexOf(2));
float f3 = descWeights.get(descWords.indexOf(3));
float f5 = descWeights.get(descWords.indexOf(5));
assertTrue(f1 > 0 && f2 > 0 && f3 > 0 && f5 > 0);
assertTrue(f1 < f2);
assertTrue(f3 < f5);
// L2-norm should be 1.0
float norm = (float) Math.sqrt(f1 * f1 + f2 * f2 + f3 * f3 + f5 * f5);
assertEquals(1.0f, norm, UtilEjml.TEST_F32);
}
use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.
the class TestECoCheckDetector method sampleBitsGray.
/**
* Create a simple scenario where the bits follow a known pattern.
*/
@Test
void sampleBitsGray() {
var points = new ArrayList<Point2D_F64>();
var values = new DogArray_F32();
int rows = 5;
int cols = 6;
int blockSize = 4;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
for (int k = 0; k < blockSize; k++) {
points.add(new Point2D_F64(j * 20, i * 20));
}
}
}
alg.bitImage.reshape(cols, rows);
alg.interpolate = new AbstractInterpolatePixelS<>() {
@Override
public float get(float x, float y) {
int i = (int) (y / 20 + 0.5);
int j = (int) (x / 20 + 0.5);
return (i + j) % 3 == 0 ? 10 : 200;
}
};
alg.samplePixelGray(points, values);
alg.graySamplesToBits(values, blockSize, 100);
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
int expected = (i + j) % 3 == 0 ? 1 : 0;
assertEquals(expected, alg.bitImage.get(j, i));
}
}
}
use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.
the class TestMultiBaselineDisparityMedian method computeFused.
/**
* Given an already constructed fused image, compute the disparity image output.
*/
@Test
void computeFused() {
var alg = new MultiBaselineDisparityMedian();
intrinsic.width = 10;
intrinsic.height = 8;
alg.initialize(intrinsic, new DoNothingPixelTransform_F64());
// add elements to each fused pixel that will be easy to compute the solution for
int counter = 0;
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 10; x++, counter++) {
for (int i = 0; i < counter; i++) {
alg.fused.get(x, y).add(i + 0.5f);
}
}
}
GrayF32 found = new GrayF32(10, 8);
assertTrue(alg.computeFused(found));
// manually compute the solution. Use a brute force approach for median value since it requires no thinking
DogArray_F32 expected = new DogArray_F32();
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 10; x++) {
if (expected.size == 0)
assertEquals(Float.MAX_VALUE, found.get(x, y), UtilEjml.TEST_F32);
else if (expected.size == 1)
assertEquals(0.5f, found.get(x, y), UtilEjml.TEST_F32);
else if (expected.size == 2)
assertEquals(1.0f, found.get(x, y), UtilEjml.TEST_F32);
else {
assertEquals(expected.data[expected.size / 2], found.get(x, y), UtilEjml.TEST_F32);
}
expected.add(expected.size + 0.5f);
}
}
}
use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.
the class ImplConvolveBox method vertical.
public static void vertical(GrayF32 input, GrayF32 output, int radius, @Nullable GrowArray<DogArray_F32> workspaces) {
workspaces = BoofMiscOps.checkDeclare(workspaces, DogArray_F32::new);
// CONCURRENT_REMOVE_LINE
final DogArray_F32 work = workspaces.grow();
final int kernelWidth = radius * 2 + 1;
final int backStep = kernelWidth * input.stride;
// CONCURRENT_BELOW BoofConcurrency.loopBlocks(radius, output.height-radius, kernelWidth, workspaces, (work, y0,y1)->{
final int y0 = radius, y1 = output.height - radius;
float[] totals = BoofMiscOps.checkDeclare(work, input.width, false);
for (int x = 0; x < input.width; x++) {
int indexIn = input.startIndex + (y0 - radius) * input.stride + x;
int indexOut = output.startIndex + output.stride * y0 + x;
float total = 0;
int indexEnd = indexIn + input.stride * kernelWidth;
for (; indexIn < indexEnd; indexIn += input.stride) {
total += input.data[indexIn];
}
totals[x] = total;
output.data[indexOut] = total;
}
// change the order it is processed in to reduce cache misses
for (int y = y0 + 1; y < y1; y++) {
int indexIn = input.startIndex + (y + radius) * input.stride;
int indexOut = output.startIndex + y * output.stride;
for (int x = 0; x < input.width; x++, indexIn++, indexOut++) {
float total = totals[x] - (input.data[indexIn - backStep]);
totals[x] = total += input.data[indexIn];
output.data[indexOut] = total;
}
}
// CONCURRENT_INLINE });
}
use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.
the class ImplConvolveMean method vertical.
public static void vertical(GrayF32 input, GrayF32 output, int offset, int length, @Nullable GrowArray<DogArray_F32> workspaces) {
workspaces = BoofMiscOps.checkDeclare(workspaces, DogArray_F32::new);
// CONCURRENT_REMOVE_LINE
final DogArray_F32 work = workspaces.grow();
final int backStep = length * input.stride;
final int offsetEnd = length - offset - 1;
final float divisor = length;
// To reduce cache misses it is processed along rows instead of going down columns, which is
// more natural for a vertical convolution. For parallel processes this requires building
// a book keeping array for each thread.
// CONCURRENT_BELOW BoofConcurrency.loopBlocks(offset, output.height - offsetEnd, length, workspaces, (work, y0,y1)->{
final int y0 = offset, y1 = output.height - offsetEnd;
float[] totals = BoofMiscOps.checkDeclare(work, input.width, false);
for (int x = 0; x < input.width; x++) {
int indexIn = input.startIndex + (y0 - offset) * input.stride + x;
int indexOut = output.startIndex + output.stride * y0 + x;
float total = 0;
int indexEnd = indexIn + input.stride * length;
for (; indexIn < indexEnd; indexIn += input.stride) {
total += input.data[indexIn];
}
totals[x] = total;
output.data[indexOut] = (total / divisor);
}
// change the order it is processed in to reduce cache misses
for (int y = y0 + 1; y < y1; y++) {
int indexIn = input.startIndex + (y + offsetEnd) * input.stride;
int indexOut = output.startIndex + y * output.stride;
for (int x = 0; x < input.width; x++, indexIn++, indexOut++) {
float total = totals[x] - (input.data[indexIn - backStep]);
totals[x] = total += input.data[indexIn];
output.data[indexOut] = (total / divisor);
}
}
// CONCURRENT_INLINE });
}
Aggregations