Search in sources :

Example 6 with TupleDesc_B

use of boofcv.struct.feature.TupleDesc_B in project BoofCV by lessthanoptimal.

the class TestDescribePointBriefSO method testOrientation.

/**
 * Checks to see if changing orientation changes the description
 */
@Test
void testOrientation() {
    GrayF32 input = createImage(width, height);
    DescribePointBriefSO<GrayF32> alg = createAlg();
    TupleDesc_B desc1 = alg.createFeature();
    TupleDesc_B desc2 = alg.createFeature();
    alg.setImage(input);
    alg.process(input.width / 2, input.height / 2, 0, briefRadius, desc1);
    alg.process(input.width / 2, input.height / 2, 1, briefRadius, desc2);
    boolean identical = true;
    for (int i = 0; i < desc1.data.length; i++) {
        if (desc1.data[i] != desc2.data[i])
            identical = false;
    }
    assertFalse(identical);
}
Also used : TupleDesc_B(boofcv.struct.feature.TupleDesc_B) GrayF32(boofcv.struct.image.GrayF32) Test(org.junit.jupiter.api.Test)

Example 7 with TupleDesc_B

use of boofcv.struct.feature.TupleDesc_B in project BoofCV by lessthanoptimal.

the class TestDescribePointBriefSO method testScale.

/**
 * Checks to see if changing orientation changes the description
 */
@Test
void testScale() {
    GrayF32 input = createImage(width, height);
    DescribePointBriefSO<GrayF32> alg = createAlg();
    TupleDesc_B desc1 = alg.createFeature();
    TupleDesc_B desc2 = alg.createFeature();
    alg.setImage(input);
    alg.process(input.width / 2, input.height / 2, 0, briefRadius, desc1);
    alg.process(input.width / 2, input.height / 2, 0, 2 * briefRadius, desc2);
    boolean identical = true;
    for (int i = 0; i < desc1.data.length; i++) {
        if (desc1.data[i] != desc2.data[i])
            identical = false;
    }
    assertFalse(identical);
}
Also used : TupleDesc_B(boofcv.struct.feature.TupleDesc_B) GrayF32(boofcv.struct.image.GrayF32) Test(org.junit.jupiter.api.Test)

Example 8 with TupleDesc_B

use of boofcv.struct.feature.TupleDesc_B in project BoofCV by lessthanoptimal.

the class ComputeMedianTuple_MT_B method countBitsInEachCluster.

@Override
protected void countBitsInEachCluster(LArrayAccessor<TupleDesc_B> points, DogArray_I32 assignments) {
    if (points.size() < minimumForConcurrent) {
        super.countBitsInEachCluster(points, assignments);
        return;
    }
    int numClusters = super.assignmentCounts.size;
    // Compute the sum of all points in each cluster
    BoofConcurrency.loopBlocks(0, points.size(), threadData, (data, idx0, idx1) -> {
        final TupleDesc_B tuple = data.point;
        final DogArray<int[]> bitCounts = data.bitCounts;
        final DogArray_I32 assignmentCounts = data.assignmentCounts;
        assignmentCounts.resetResize(numClusters, 0);
        bitCounts.resize(numClusters);
        for (int i = 0; i < bitCounts.size; i++) {
            Arrays.fill(bitCounts.data[i], 0);
        }
        // Compute the sum of all points in each cluster
        for (int pointIdx = idx0; pointIdx < idx1; pointIdx++) {
            // See which cluster this point was assigned to and increment its counter
            int clusterIdx = assignments.get(pointIdx);
            assignmentCounts.data[clusterIdx]++;
            points.getCopy(pointIdx, tuple);
            // Increment the counter for each "true" bit in the tuple
            int[] bitCount = bitCounts.get(clusterIdx);
            int bit = 0;
            while (bit + 32 < dof) {
                // Unroll for speed
                int value = tuple.data[bit / 32];
                if ((value & 0x00000001) != 0)
                    bitCount[bit]++;
                if ((value & 0x00000002) != 0)
                    bitCount[bit + 1]++;
                if ((value & 0x00000004) != 0)
                    bitCount[bit + 2]++;
                if ((value & 0x00000008) != 0)
                    bitCount[bit + 3]++;
                if ((value & 0x00000010) != 0)
                    bitCount[bit + 4]++;
                if ((value & 0x00000020) != 0)
                    bitCount[bit + 5]++;
                if ((value & 0x00000040) != 0)
                    bitCount[bit + 6]++;
                if ((value & 0x00000080) != 0)
                    bitCount[bit + 7]++;
                if ((value & 0x00000100) != 0)
                    bitCount[bit + 8]++;
                if ((value & 0x00000200) != 0)
                    bitCount[bit + 9]++;
                if ((value & 0x00000400) != 0)
                    bitCount[bit + 10]++;
                if ((value & 0x00000800) != 0)
                    bitCount[bit + 11]++;
                if ((value & 0x00001000) != 0)
                    bitCount[bit + 12]++;
                if ((value & 0x00002000) != 0)
                    bitCount[bit + 13]++;
                if ((value & 0x00004000) != 0)
                    bitCount[bit + 14]++;
                if ((value & 0x00008000) != 0)
                    bitCount[bit + 15]++;
                if ((value & 0x00010000) != 0)
                    bitCount[bit + 16]++;
                if ((value & 0x00020000) != 0)
                    bitCount[bit + 17]++;
                if ((value & 0x00040000) != 0)
                    bitCount[bit + 18]++;
                if ((value & 0x00080000) != 0)
                    bitCount[bit + 19]++;
                if ((value & 0x00100000) != 0)
                    bitCount[bit + 20]++;
                if ((value & 0x00200000) != 0)
                    bitCount[bit + 21]++;
                if ((value & 0x00400000) != 0)
                    bitCount[bit + 22]++;
                if ((value & 0x00800000) != 0)
                    bitCount[bit + 23]++;
                if ((value & 0x01000000) != 0)
                    bitCount[bit + 24]++;
                if ((value & 0x02000000) != 0)
                    bitCount[bit + 25]++;
                if ((value & 0x04000000) != 0)
                    bitCount[bit + 26]++;
                if ((value & 0x08000000) != 0)
                    bitCount[bit + 27]++;
                if ((value & 0x10000000) != 0)
                    bitCount[bit + 28]++;
                if ((value & 0x20000000) != 0)
                    bitCount[bit + 29]++;
                if ((value & 0x40000000) != 0)
                    bitCount[bit + 30]++;
                if ((value & 0x80000000) != 0)
                    bitCount[bit + 31]++;
                bit += 32;
            }
            // handle the remainder if it doesn't align with 32-bit integers
            for (; bit < dof; bit++) {
                if (!tuple.isBitTrue(bit))
                    continue;
                bitCount[bit]++;
            }
        }
    });
    // stitch all the threads back together
    for (int threadIdx = 0; threadIdx < threadData.size(); threadIdx++) {
        ThreadData data = threadData.get(threadIdx);
        for (int clusterIdx = 0; clusterIdx < numClusters; clusterIdx++) {
            super.assignmentCounts.data[clusterIdx] += data.assignmentCounts.data[clusterIdx];
            int[] allCounts = super.bitCounts.get(clusterIdx);
            int[] threadCounts = data.bitCounts.get(clusterIdx);
            for (int bitIdx = 0; bitIdx < dof; bitIdx++) {
                allCounts[bitIdx] += threadCounts[bitIdx];
            }
        }
    }
}
Also used : TupleDesc_B(boofcv.struct.feature.TupleDesc_B) DogArray_I32(org.ddogleg.struct.DogArray_I32)

Example 9 with TupleDesc_B

use of boofcv.struct.feature.TupleDesc_B in project BoofCV by lessthanoptimal.

the class TestComputeMedianTuple_MT_B method compare.

@Test
void compare() {
    int DOF = 510;
    int numClusters = 4;
    // Create a list of random points
    List<TupleDesc_B> list = new ArrayList<>();
    var assignments = new DogArray_I32(1000);
    for (int i = 0; i < 1000; i++) {
        assignments.add(rand.nextInt(numClusters));
        var t = new TupleDesc_B(DOF);
        for (int j = 0; j < t.data.length; j++) {
            t.data[j] = rand.nextInt();
        }
        list.add(t);
    }
    var points = new ListAccessor<>(list, (src, dst) -> dst.setTo(src), TupleDesc_B.class);
    var clustersSingle = new DogArray<>(() -> new TupleDesc_B(DOF));
    var clustersMulti = new DogArray<>(() -> new TupleDesc_B(DOF));
    clustersSingle.resize(numClusters);
    clustersMulti.resize(numClusters);
    var single = new ComputeMedianTuple_B(DOF);
    var multi = new ComputeMedianTuple_MT_B(DOF);
    single.process(points, assignments, clustersSingle);
    multi.process(points, assignments, clustersMulti);
    assertEquals(clustersSingle.size, clustersMulti.size);
    for (int i = 0; i < numClusters; i++) {
        assertArrayEquals(clustersSingle.get(i).data, clustersMulti.get(i).data);
    }
}
Also used : ListAccessor(org.ddogleg.clustering.misc.ListAccessor) TupleDesc_B(boofcv.struct.feature.TupleDesc_B) ArrayList(java.util.ArrayList) DogArray_I32(org.ddogleg.struct.DogArray_I32) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Example 10 with TupleDesc_B

use of boofcv.struct.feature.TupleDesc_B in project BoofCV by lessthanoptimal.

the class TestTuplePointDistanceHamming method addToPoint.

/**
 * This is a bit tricky. Magnitude makes no sense for a binary descriptor. Instead we will flip more bits
 */
@Override
protected TupleDesc_B addToPoint(TupleDesc_B src, double magnitude) {
    TupleDesc_B dst = src.newInstance();
    System.arraycopy(src.data, 0, dst.data, 0, src.data.length);
    // decide on how many bits to flip based on the magnitude of the requested change
    int flip = (int) (src.size() * magnitude / 10.0);
    // Randomly select bits to flip
    for (int i = 0; i < flip; i++) {
        int bit = rand.nextInt(src.size());
        dst.setBit(bit, !src.isBitTrue(bit));
    }
    return dst;
}
Also used : TupleDesc_B(boofcv.struct.feature.TupleDesc_B)

Aggregations

TupleDesc_B (boofcv.struct.feature.TupleDesc_B)24 Test (org.junit.jupiter.api.Test)14 GrayF32 (boofcv.struct.image.GrayF32)11 Random (java.util.Random)6 ScoreAssociateHamming_B (boofcv.abst.feature.associate.ScoreAssociateHamming_B)4 ConfigGeneralDetector (boofcv.abst.feature.detect.interest.ConfigGeneralDetector)4 Point2D_I32 (georegression.struct.point.Point2D_I32)4 AssociateDescTo2D (boofcv.abst.feature.associate.AssociateDescTo2D)2 WrapDescribeBrief (boofcv.abst.feature.describe.WrapDescribeBrief)2 EasyGeneralFeatureDetector (boofcv.alg.feature.detect.interest.EasyGeneralFeatureDetector)2 DogArray_I32 (org.ddogleg.struct.DogArray_I32)2 DetectDescribeFusion (boofcv.abst.feature.detdesc.DetectDescribeFusion)1 AssociateMaxDistanceNaive (boofcv.alg.feature.associate.AssociateMaxDistanceNaive)1 FactoryGImageGray (boofcv.core.image.FactoryGImageGray)1 GImageGray (boofcv.core.image.GImageGray)1 ArrayList (java.util.ArrayList)1 ListAccessor (org.ddogleg.clustering.misc.ListAccessor)1 DogArray (org.ddogleg.struct.DogArray)1