use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImageStatistics method testVariance.
private void testVariance(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageGray inputA = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
if (inputA.getDataType().isSigned()) {
GImageMiscOps.fillUniform(inputA, rand, -20, 20);
} else {
GImageMiscOps.fillUniform(inputA, rand, 0, 20);
}
double mean = 2.5;
Object result = paramTypes[1] == double.class ? m.invoke(null, inputA, mean) : m.invoke(null, inputA, (float) mean);
double total = 0;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
double d = GeneralizedImageOps.get(inputA, j, i) - mean;
total += d * d;
}
}
double var = total / (width * height);
assertEquals(var, ((Number) result).doubleValue(), 1e-4);
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestPixelMath method testBound.
private void testBound(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageGray input = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
double max = 100;
double min = -100;
GImageMiscOps.fillUniform(input, rand, (int) min, (int) max);
if (input.getDataType().isInteger()) {
m.invoke(null, input, 2, 10);
} else
m.invoke(null, input, 2.0f, 10.0f);
GImageGray a = FactoryGImageGray.wrap(input);
if (input.getDataType().isInteger()) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int v = a.get(j, i).intValue();
assertTrue(v >= 2 && v <= 10);
}
}
} else {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
float v = a.get(j, i).floatValue();
assertTrue(v >= 2f && v <= 10f);
}
}
}
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestPixelMath method testPow2.
private void testPow2(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageGray inputA = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
ImageGray inputB = GeneralizedImageOps.createSingleBand(paramTypes[1], width, height);
GImageMiscOps.fillUniform(inputA, rand, -20, 20);
GImageMiscOps.fillUniform(inputB, rand, -20, 20);
m.invoke(null, inputA, inputB);
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
double a = GeneralizedImageOps.get(inputA, j, i);
double b = GeneralizedImageOps.get(inputB, j, i);
assertEquals(a * a, b, 1e-4);
}
}
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestPixelMath method testMultiplyPixel.
private void testMultiplyPixel(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageGray inputA = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
ImageGray inputB = GeneralizedImageOps.createSingleBand(paramTypes[1], width, height);
ImageGray output = GeneralizedImageOps.createSingleBand(paramTypes[2], width, height);
GImageMiscOps.fillUniform(inputA, rand, -20, 20);
GImageMiscOps.fillUniform(inputB, rand, -20, 20);
m.invoke(null, inputA, inputB, output);
GImageGray a = FactoryGImageGray.wrap(inputA);
GImageGray b = FactoryGImageGray.wrap(inputB);
GImageGray o = FactoryGImageGray.wrap(output);
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
assertEquals(a.get(j, i).doubleValue() * b.get(j, i).doubleValue(), o.get(j, i).doubleValue(), 1e-4);
}
}
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestPixelMath method testAdd.
private void testAdd(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageGray inputA = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
ImageGray inputB = GeneralizedImageOps.createSingleBand(paramTypes[1], width, height);
ImageGray inputC = GeneralizedImageOps.createSingleBand(paramTypes[2], width, height);
if (inputA.getDataType().isSigned()) {
GImageMiscOps.fillUniform(inputA, rand, -20, 20);
GImageMiscOps.fillUniform(inputB, rand, -20, 20);
} else {
GImageMiscOps.fillUniform(inputA, rand, 0, 20);
GImageMiscOps.fillUniform(inputB, rand, -20, 20);
}
m.invoke(null, inputA, inputB, inputC);
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
double a = GeneralizedImageOps.get(inputA, j, i);
double b = GeneralizedImageOps.get(inputB, j, i);
double c = GeneralizedImageOps.get(inputC, j, i);
assertEquals(a + b, c, 1e-4);
}
}
}
Aggregations