use of boofcv.struct.feature.TupleDesc_B in project BoofCV by lessthanoptimal.
the class BaseTestDescribePointBinaryCompare method testImageBorder.
/**
* See if the border is handled correctly
*/
@Test
void testImageBorder() {
T input = createImage(width, height);
DescribePointBinaryCompare<T> alg = createAlg(def);
alg.setImage(input);
TupleDesc_B desc = createFeature();
// just see if it blows up for now. a more rigorous test would be better
alg.process(0, 0, desc);
alg.process(width - 1, height - 1, desc);
// if given a point inside it should produce the same answer
alg.processBorder(width / 2, height / 2, desc);
TupleDesc_B descInside = createFeature();
alg.processInside(width / 2, height / 2, descInside);
for (int i = 0; i < desc.numBits; i++) assertEquals(desc.getDouble(i), descInside.getDouble(i), 1e-8);
}
use of boofcv.struct.feature.TupleDesc_B in project BoofCV by lessthanoptimal.
the class BaseTestDescribePointBinaryCompare method testManualCheck.
/**
* Compute the descriptor manually and see if it gets the same answer
*/
@Test
void testManualCheck() {
T input = createImage(width, height);
GImageGray a = FactoryGImageGray.wrap(input);
DescribePointBinaryCompare<T> alg = createAlg(def);
alg.setImage(input);
int c_x = input.width / 2;
int c_y = input.height / 2;
TupleDesc_B desc = createFeature();
alg.process(c_x, c_y, desc);
for (int i = 0; i < def.compare.length; i++) {
Point2D_I32 c = def.compare[i];
Point2D_I32 p0 = def.samplePoints[c.x];
Point2D_I32 p1 = def.samplePoints[c.y];
boolean expected = a.get(c_x + p0.x, c_y + p0.y).doubleValue() < a.get(c_x + p1.x, c_y + p1.y).doubleValue();
assertTrue(expected == desc.isBitTrue(def.compare.length - i - 1));
}
}
use of boofcv.struct.feature.TupleDesc_B in project BoofCV by lessthanoptimal.
the class ComputeMedianTuple_B method countsToBits.
protected void countsToBits(FastAccess<TupleDesc_B> clusters) {
// If 50% of a bit was observed to be true for a cluster, set that bit to true
for (int clusterIdx = 0; clusterIdx < clusters.size; clusterIdx++) {
int[] bitCount = bitCounts.get(clusterIdx);
// If more than 1/2 the points in this cluster had a positive value for a bit then the output will be 1
int threshold = assignmentCounts.get(clusterIdx) / 2;
TupleDesc_B cluster = clusters.get(clusterIdx);
// shouldn't be necessary, but this way we know if there are extra bits in the array they are all zero
Arrays.fill(cluster.data, 0);
for (int i = 0; i < dof; i++) {
cluster.setBit(i, bitCount[i] > threshold);
}
}
}
use of boofcv.struct.feature.TupleDesc_B in project BoofCV by lessthanoptimal.
the class ComputeMedianTuple_B method countBitsInEachCluster.
/**
* Goes through each point and counts the number of bits are true in each cluster its assigned to
*/
protected void countBitsInEachCluster(LArrayAccessor<TupleDesc_B> points, DogArray_I32 assignments) {
// Compute the sum of all points in each cluster
for (int pointIdx = 0; pointIdx < points.size(); pointIdx++) {
// See which cluster this point was assigned to and increment its counter
int clusterIdx = assignments.get(pointIdx);
assignmentCounts.data[clusterIdx]++;
TupleDesc_B tuple = points.getTemp(pointIdx);
// 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]++;
}
}
}
Aggregations