use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestImageStatistics method testMaxAbs.
private void testMaxAbs(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageBase input = GeneralizedImageOps.createImage(paramTypes[0], width, height, numBands);
if (input.getImageType().getDataType().isSigned()) {
GImageMiscOps.fillUniform(input, rand, -20, 19);
GeneralizedImageOps.setB(input, 0, 3, 0, -100);
} else {
GImageMiscOps.fillUniform(input, rand, 0, 19);
GeneralizedImageOps.setB(input, 0, 3, 0, 100);
}
Number o = (Number) m.invoke(null, input);
assertEquals(100, o.doubleValue(), 1e-8);
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestImageStatistics method testMin.
private void testMin(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageBase input = GeneralizedImageOps.createImage(paramTypes[0], width, height, numBands);
if (input.getImageType().getDataType().isSigned()) {
GImageMiscOps.fillUniform(input, rand, -20, -5);
GeneralizedImageOps.setB(input, 0, 3, 0, -30);
Number o = (Number) m.invoke(null, input);
assertEquals(-30, o.doubleValue(), 1e-8);
} else {
double maxValue = input.getImageType().getDataType().getMaxValue();
GImageMiscOps.fillUniform(input, rand, 100, maxValue);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
double before = GeneralizedImageOps.get(input, x, y, 0);
GeneralizedImageOps.setB(input, x, y, 0, 5);
Number o = (Number) m.invoke(null, input);
assertEquals(5, o.doubleValue(), 1e-8);
GeneralizedImageOps.setB(input, x, y, 0, before);
}
}
}
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestImageStatistics method testSum.
private void testSum(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageBase inputA = GeneralizedImageOps.createImage(paramTypes[0], width, height, numBands);
int numBands = inputA.getImageType().getNumBands();
if (inputA.getImageType().getDataType().isSigned()) {
GImageMiscOps.fillUniform(inputA, rand, -20, 20);
} else {
GImageMiscOps.fillUniform(inputA, rand, 0, 20);
}
Object result = m.invoke(null, inputA);
double expected = 0;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
for (int k = 0; k < numBands; k++) {
expected += GeneralizedImageOps.get(inputA, j, i, k);
}
}
}
double found = ((Number) result).doubleValue();
assertEquals(expected, found, 1e-3);
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestPixelMath method testInvert.
private void testInvert(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageBase inputA = GeneralizedImageOps.createImage(paramTypes[0], width, height, numBands);
ImageBase inputB = GeneralizedImageOps.createImage(paramTypes[1], width, height, numBands);
int numBands = inputA.getImageType().getNumBands();
if (inputA.getImageType().getDataType().isSigned()) {
GImageMiscOps.fillUniform(inputA, rand, -20, 20);
} else {
throw new RuntimeException("Shouldn't be used on unsigned images");
}
m.invoke(null, inputA, inputB);
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
for (int k = 0; k < numBands; k++) {
double a = GeneralizedImageOps.get(inputA, j, i, k);
double b = GeneralizedImageOps.get(inputB, j, i, k);
assertEquals(a, -b, 1e-4);
}
}
}
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestPixelMath method testDivideBounded.
private void testDivideBounded(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageBase input = GeneralizedImageOps.createImage(paramTypes[0], width, height, numBands);
ImageBase output = GeneralizedImageOps.createImage(paramTypes[4], width, height, numBands);
GImageMiscOps.fillUniform(input, rand, 0, 20);
int numBands = input.getImageType().getNumBands();
if (input.getImageType().getDataType().isSigned()) {
GImageMiscOps.fillUniform(input, rand, -20, 20);
} else {
GImageMiscOps.fillUniform(input, rand, 0, 20);
}
if (input.getImageType().getDataType().isInteger())
m.invoke(null, input, 10, -1, 1, output);
else
m.invoke(null, input, 10.0f, -1f, 1f, output);
float tol = input.getImageType().getDataType().isInteger() ? 1 : 1e-4f;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
for (int k = 0; k < numBands; k++) {
double expected = GeneralizedImageOps.get(input, j, i, k) / 10.0f;
double found = GeneralizedImageOps.get(output, j, i, k);
if (expected < -1)
expected = -1;
if (expected > 1)
expected = 1;
assertEquals(expected, found, tol);
}
}
}
}
Aggregations