Search in sources :

Example 46 with TupleDesc_F64

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);
}
Also used : TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) Test(org.junit.Test)

Example 47 with TupleDesc_F64

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);
}
Also used : TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) Test(org.junit.Test)

Example 48 with TupleDesc_F64

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);
    }
}
Also used : TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 49 with TupleDesc_F64

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);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) Point2D_I32(georegression.struct.point.Point2D_I32) Test(org.junit.Test)

Example 50 with TupleDesc_F64

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)));
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)66 Test (org.junit.Test)47 GrayF32 (boofcv.struct.image.GrayF32)17 GrayU8 (boofcv.struct.image.GrayU8)8 Point2D_I32 (georegression.struct.point.Point2D_I32)6 TupleDesc_S8 (boofcv.struct.feature.TupleDesc_S8)5 ArrayList (java.util.ArrayList)5 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)4 BufferedImage (java.awt.image.BufferedImage)4 File (java.io.File)4 DescribeRegionPoint (boofcv.abst.feature.describe.DescribeRegionPoint)3 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)3 TupleDesc_U8 (boofcv.struct.feature.TupleDesc_U8)3 Planar (boofcv.struct.image.Planar)3 Point3D_F64 (georegression.struct.point.Point3D_F64)3 HistogramScene (boofcv.alg.scene.HistogramScene)2 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)2 ImageGray (boofcv.struct.image.ImageGray)2 IOException (java.io.IOException)2 FastQueue (org.ddogleg.struct.FastQueue)2