use of boofcv.struct.feature.TupleDesc_F64 in project BoofCV by lessthanoptimal.
the class TestDescribeSiftCommon method normalizeDescriptor.
@Test
public void normalizeDescriptor() {
TupleDesc_F64 descriptor = new TupleDesc_F64(128);
descriptor.value[5] = 100;
descriptor.value[20] = 120;
descriptor.value[60] = 20;
DescribeSiftCommon alg = new DescribeSiftCommon(4, 4, 8, 0.5, 0.2);
alg.normalizeDescriptor(descriptor, alg.maxDescriptorElementValue);
assertEquals(1, normL2(descriptor), 1e-8);
// cropping should make 5 and 20 the same
assertEquals(descriptor.value[5], descriptor.value[20], 1e-8);
}
use of boofcv.struct.feature.TupleDesc_F64 in project BoofCV by lessthanoptimal.
the class TestDescribeSiftCommon method trilinearInterpolation.
/**
* Tests trilinear interpolation by checking out some of its properties instead of its value
* exactly
*/
@Test
public void trilinearInterpolation() {
DescribeSiftCommon alg = new DescribeSiftCommon(4, 4, 8, 0.5, 0.2);
TupleDesc_F64 descriptor = new TupleDesc_F64(128);
// in the middle of the feature, the total amount added to the descriptor should equal the input weight
// upper edges will have a value less than the input weight
alg.trilinearInterpolation(2.0f, 1.25f, 2.0f, 0.5, descriptor);
double sum = 0;
int count = 0;
for (int i = 0; i < descriptor.size(); i++) {
sum += descriptor.value[i];
if (descriptor.value[i] != 0)
count++;
}
assertEquals(2.0, sum, 1e-6);
assertTrue(count > 1);
// try an edge case
sum = 0;
descriptor.fill(0);
alg.trilinearInterpolation(2.0f, 3.25f, 3.25f, 0.5, descriptor);
for (int i = 0; i < descriptor.size(); i++) {
sum += descriptor.value[i];
}
assertEquals(2.0 * 0.75 * 0.75 * 1.0, sum, 1e-8);
// now have something exactly at the start of a bin. all the weight should be in one location
descriptor.fill(0);
alg.trilinearInterpolation(2.0f, 3f, 3f, 2 * Math.PI / 8, descriptor);
count = 0;
for (int i = 0; i < descriptor.size(); i++) {
double weight = descriptor.value[i];
if (weight > 0) {
assertEquals(2.0, weight, 1e-8);
count++;
}
}
assertEquals(1, count);
}
use of boofcv.struct.feature.TupleDesc_F64 in project BoofCV by lessthanoptimal.
the class TestHistogramFeatureOps method histogram_PL_U8_compareToSingle.
/**
* Compare to single band image. Results should be identical
*/
@Test
public void histogram_PL_U8_compareToSingle() {
GrayU8 image = new GrayU8(width, height);
ImageMiscOps.fillUniform(image, rand, 0, 255);
Planar<GrayU8> ms = new Planar<>(GrayU8.class, width, height, 1);
ms.setBand(0, image);
TupleDesc_F64 expected = new TupleDesc_F64(256);
Histogram_F64 found = new Histogram_F64(256);
found.setRange(0, 0, 255);
HistogramFeatureOps.histogram(image, 255, expected);
HistogramFeatureOps.histogram_U8(ms, found);
for (int i = 0; i < found.size(); i++) {
assertEquals(expected.getDouble(i), found.getDouble(i), 1e-8);
}
}
use of boofcv.struct.feature.TupleDesc_F64 in project BoofCV by lessthanoptimal.
the class TestDescribeDenseHogFastAlg method computeDescriptor.
@Test
public void computeDescriptor() {
DescribeDenseHogFastAlg<GrayF32> helper = new DescribeDenseHogFastAlg<>(10, 8, 2, 2, 1, imageType);
helper.growCellArray(imgWidth, imgHeight);
int stride = helper.cellCols;
// manually build a simple histogram for input and manually construct the expected resulting descriptor
TupleDesc_F64 expected = new TupleDesc_F64(40);
setHistogram(helper.cells[2].histogram, 2, 3, expected.value, 0);
setHistogram(helper.cells[3].histogram, 2, 3, expected.value, 10);
setHistogram(helper.cells[stride + 2].histogram, 5, 0, expected.value, 20);
setHistogram(helper.cells[stride + 3].histogram, 7, 8, expected.value, 30);
DescribeSiftCommon.normalizeDescriptor(expected, 0.2);
helper.computeDescriptor(0, 2);
Point2D_I32 where = helper.locations.get(0);
TupleDesc_F64 found = helper.descriptions.get(0);
assertEquals(8 * 2, where.x);
assertEquals(0, where.y);
assertEquals(40, found.size());
assertTrue(DescriptorDistance.euclidean(expected, found) < 1e-8);
}
use of boofcv.struct.feature.TupleDesc_F64 in project BoofCV by lessthanoptimal.
the class TestDescribeDenseHogFastAlg method getDescriptorsInRegion.
@Test
public void getDescriptorsInRegion() {
int x0 = 5, x1 = 67;
int y0 = 9, y1 = 89;
DescribeDenseHogFastAlg<GrayF32> helper = new DescribeDenseHogFastAlg<>(10, 8, 2, 2, 1, imageType);
GrayF32 input = new GrayF32(120, 110);
helper.setInput(input);
helper.process();
List<TupleDesc_F64> expected = new ArrayList<>();
// use a different more brute force technique to find all the descriptors contained inside the region
// take advantage of the descriptors being computed in a row major order
int c = 8;
int w = 2 * c;
for (int y = 0; y < input.height - w; y += c) {
int i = (y / c) * helper.cellCols;
for (int x = 0; x < input.width - w; x += c, i++) {
if (x >= x0 && x + w < x1 && y >= y0 && y + w < y1) {
expected.add(helper.getDescriptions().get(i));
}
}
}
List<TupleDesc_F64> found = new ArrayList<>();
helper.getDescriptorsInRegion(x0, y0, x1, y1, found);
assertEquals(expected.size(), found.size());
for (int j = 0; j < expected.size(); j++) {
assertTrue(found.contains(expected.get(j)));
}
}
Aggregations