use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class TestMultiViewIO method checkIdentical.
private void checkIdentical(SceneWorkingGraph a, SceneWorkingGraph b) {
assertEquals(a.listCameras.size(), b.listCameras.size());
assertEquals(a.listViews.size(), b.listViews.size());
assertEquals(a.views.size(), b.views.size());
for (int cameraIdx = 0; cameraIdx < a.listCameras.size(); cameraIdx++) {
SceneWorkingGraph.Camera ca = a.listCameras.get(cameraIdx);
SceneWorkingGraph.Camera cb = b.listCameras.get(cameraIdx);
assertEquals(ca.indexDB, cb.indexDB);
assertEquals(ca.localIndex, cb.localIndex);
assertEquals(ca.prior.fx, cb.prior.fx);
assertEquals(ca.intrinsic.f, cb.intrinsic.f);
}
for (int viewIdx = 0; viewIdx < a.listViews.size(); viewIdx++) {
SceneWorkingGraph.View va = a.listViews.get(viewIdx);
SceneWorkingGraph.View vb = b.listViews.get(viewIdx);
assertSame(va, a.views.get(va.pview.id));
assertSame(vb, b.views.get(vb.pview.id));
assertEquals(0.0, va.world_to_view.T.distance(vb.world_to_view.T), UtilEjml.EPS);
assertTrue(MatrixFeatures_DDRM.isEquals(va.world_to_view.R, vb.world_to_view.R, UtilEjml.EPS));
assertEquals(va.inliers.size, vb.inliers.size);
for (int inlierInfo = 0; inlierInfo < va.inliers.size; inlierInfo++) {
SceneWorkingGraph.InlierInfo infoa = va.inliers.get(inlierInfo);
SceneWorkingGraph.InlierInfo infob = vb.inliers.get(inlierInfo);
assertEquals(infoa.observations.size, infob.observations.size);
final int numViews = infoa.views.size;
for (int i = 0; i < numViews; i++) {
assertEquals(infoa.views.get(i).id, infob.views.get(i).id);
DogArray_I32 oa = infoa.observations.get(i);
DogArray_I32 ob = infob.observations.get(i);
assertEquals(oa.size, ob.size);
oa.forIdx((idx, v) -> assertEquals(v, ob.get(idx)));
}
}
}
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class TestMultiViewIO method createWorkingGraph.
private SceneWorkingGraph createWorkingGraph(PairwiseImageGraph pairwise) {
var ret = new SceneWorkingGraph();
// Add a camera for each view
for (int cameraIdx = 0; cameraIdx < pairwise.nodes.size; cameraIdx++) {
SceneWorkingGraph.Camera c = ret.addCamera(cameraIdx);
c.intrinsic.f = rand.nextDouble();
c.intrinsic.k1 = rand.nextDouble();
c.intrinsic.k2 = rand.nextDouble();
c.prior.fx = rand.nextDouble();
}
pairwise.nodes.forIdx((i, v) -> ret.addView(v, ret.listCameras.get(i)));
var candidates = DogArray_I32.range(0, pairwise.nodes.size);
ret.listViews.forEach(v -> {
SpecialEuclideanOps_F64.eulerXyz(rand.nextDouble(), rand.nextDouble(), rand.nextDouble(), rand.nextDouble(), rand.nextDouble(), rand.nextDouble(), v.world_to_view);
RandomMatrices_DDRM.fillUniform(v.projective, rand);
PrimitiveArrays.shuffle(candidates.data, 0, candidates.size, rand);
v.inliers.resetResize(2);
for (int infoIdx = 0; infoIdx < v.inliers.size; infoIdx++) {
SceneWorkingGraph.InlierInfo inlier = v.inliers.get(infoIdx);
int numViews = rand.nextInt(Math.min(5, candidates.size));
int numObs = rand.nextInt(20) + 1;
inlier.views.resize(numViews);
inlier.observations.resize(numViews);
for (int i = 0; i < numViews; i++) {
inlier.views.set(i, pairwise.nodes.get(candidates.get(i)));
DogArray_I32 obs = inlier.observations.get(i);
obs.resize(numObs);
for (int j = 0; j < numObs; j++) {
obs.data[j] = rand.nextInt();
}
}
}
});
return ret;
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class TestStereoMutualInformation method cost_minimum.
/**
* Given that it's know that the left and right images have the same histograms, see if the same pixel
* values have the minimum costs
*/
@Test
void cost_minimum() {
int invalid = 10;
int maxValue = 20;
renderStereoRandom(0, maxValue - 1, 8, invalid);
StereoMutualInformation alg = new StereoMutualInformation();
alg.configureHistogram(maxValue);
alg.configureSmoothing(1);
alg.process(left, right, 0, disparityTruth, invalid);
alg.precomputeScaledCost(SgmDisparityCost.MAX_COST);
// Get a list of values in the left and right image
// Mutual information isn't designed to handle cases where you attempt to match up with a non-existing pixel
DogArray_I32 valuesLeft = new DogArray_I32();
DogArray_I32 valuesRight = new DogArray_I32();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (disparityTruth.get(x, y) == invalid)
continue;
if (!valuesLeft.contains(left.get(x, y)))
valuesLeft.add(left.get(x, y));
if (!valuesRight.contains(right.get(x, y)))
valuesRight.add(right.get(x, y));
}
}
// dont' consider values not in the left image since those are kinda undefined
for (int i = 0; i < valuesLeft.size; i++) {
int bestScore = Integer.MAX_VALUE;
int bestVR = -1;
int vl = valuesLeft.get(i);
for (int j = 0; j < valuesRight.size; j++) {
int c = alg.costScaled(vl, valuesRight.get(j));
if (c < bestScore) {
bestScore = c;
bestVR = valuesRight.get(j);
}
}
// System.out.println("left="+vl+" right="+bestVR+" score="+bestScore);
assertEquals(vl, bestVR);
}
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class ImplEnhanceHistogram method equalizeLocalNaive.
/**
* Inefficiently computes the local histogram, but can handle every possible case for image size and
* local region size
*/
public static void equalizeLocalNaive(GrayU8 input, int radius, int histogramLength, GrayU8 output, GrowArray<DogArray_I32> workspaces) {
// CONCURRENT_REMOVE_LINE
final DogArray_I32 work = workspaces.grow();
final int width = 2 * radius + 1;
final int maxValue = histogramLength - 1;
// CONCURRENT_BELOW BoofConcurrency.loopBlocks(0,input.height,workspaces,(work,idx0,idx1)->{
int idx0 = 0, idx1 = input.height;
int[] histogram = BoofMiscOps.checkDeclare(work, histogramLength, false);
for (int y = idx0; y < idx1; y++) {
// make sure it's inside the image bounds
int y0 = y - radius;
int y1 = y + radius + 1;
if (y0 < 0) {
y0 = 0;
y1 = width;
if (y1 > input.height)
y1 = input.height;
} else if (y1 > input.height) {
y1 = input.height;
y0 = y1 - width;
if (y0 < 0)
y0 = 0;
}
// pixel indexes
int indexIn = input.startIndex + y * input.stride;
int indexOut = output.startIndex + y * output.stride;
for (int x = 0; x < input.width; x++) {
// make sure it's inside the image bounds
int x0 = x - radius;
int x1 = x + radius + 1;
if (x0 < 0) {
x0 = 0;
x1 = width;
if (x1 > input.width)
x1 = input.width;
} else if (x1 > input.width) {
x1 = input.width;
x0 = x1 - width;
if (x0 < 0)
x0 = 0;
}
// compute the local histogram
localHistogram(input, x0, y0, x1, y1, histogram);
// only need to compute up to the value of the input pixel
int inputValue = input.data[indexIn++] & 0xFF;
int sum = 0;
for (int i = 0; i <= inputValue; i++) {
sum += histogram[i];
}
int area = (y1 - y0) * (x1 - x0);
output.data[indexOut++] = (byte) ((sum * maxValue) / area);
}
}
// CONCURRENT_ABOVE }});
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class ImplEnhanceHistogram method equalizeLocalInner.
/**
* Performs local histogram equalization just on the inner portion of the image
*/
public static void equalizeLocalInner(GrayU8 input, int radius, int histogramLength, GrayU8 output, GrowArray<DogArray_I32> workspaces) {
// CONCURRENT_REMOVE_LINE
final DogArray_I32 work = workspaces.grow();
int width = 2 * radius + 1;
int area = width * width;
int maxValue = histogramLength - 1;
// CONCURRENT_BELOW BoofConcurrency.loopBlocks(radius,input.height-radius,workspaces,(work,y0,y1)->{
int y0 = radius, y1 = input.height - radius;
int[] histogram = BoofMiscOps.checkDeclare(work, histogramLength, false);
for (int y = y0; y < y1; y++) {
localHistogram(input, 0, y - radius, width, y + radius + 1, histogram);
// compute equalized pixel value using the local histogram
int inputValue = input.unsafe_get(radius, y);
int sum = 0;
for (int i = 0; i <= inputValue; i++) {
sum += histogram[i];
}
output.set(radius, y, (sum * maxValue) / area);
// start of old and new columns in histogram region
int indexOld = input.startIndex + y * input.stride;
int indexNew = indexOld + width;
// index of pixel being examined
int indexIn = input.startIndex + y * input.stride + radius + 1;
int indexOut = output.startIndex + y * output.stride + radius + 1;
for (int x = radius + 1; x < input.width - radius; x++) {
// update local histogram by removing the left column
for (int i = -radius; i <= radius; i++) {
histogram[input.data[indexOld + i * input.stride] & 0xFF]--;
}
// update local histogram by adding the right column
for (int i = -radius; i <= radius; i++) {
histogram[input.data[indexNew + i * input.stride] & 0xFF]++;
}
// compute equalized pixel value using the local histogram
inputValue = input.data[indexIn++] & 0xFF;
sum = 0;
for (int i = 0; i <= inputValue; i++) {
sum += histogram[i];
}
output.data[indexOut++] = (byte) ((sum * maxValue) / area);
indexOld++;
indexNew++;
}
}
// CONCURRENT_ABOVE }});
}
Aggregations