use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestPixelMath method testMultiplyBounded.
private void testMultiplyBounded(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, 2, -30, 30, output);
else
m.invoke(null, input, 2.0f, -30f, 30f, output);
float tol = input.getImageType().getDataType().isInteger() ? 1 : 1e-4f;
GImageMultiBand a = FactoryGImageMultiBand.wrap(input);
GImageMultiBand b = FactoryGImageMultiBand.wrap(output);
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
a.get(j, i, pixelA);
b.get(j, i, pixelB);
for (int k = 0; k < numBands; k++) {
float expected = pixelA[k] * 2;
float found = pixelB[k];
if (expected < -30)
expected = -30;
if (expected > 30)
expected = 30;
assertEquals(expected, found, tol);
}
}
}
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestPixelMath method testMinus.
private void testMinus(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
boolean imageFirst = ImageBase.class.isAssignableFrom(paramTypes[0]);
int indexImg = imageFirst ? 0 : 1;
ImageBase input = GeneralizedImageOps.createImage(paramTypes[indexImg], width, height, numBands);
ImageBase output = GeneralizedImageOps.createImage(paramTypes[indexImg], width, height, numBands);
int numBands = input.getImageType().getNumBands();
float val = imageFirst ? 2 : 20;
Object scalar;
if (input.getImageType().getDataType().isInteger()) {
if (imageFirst) {
GImageMiscOps.fillUniform(input, rand, 10, 25);
} else {
GImageMiscOps.fillUniform(input, rand, 3, 10);
}
scalar = (int) val;
} else {
GImageMiscOps.fillUniform(input, rand, -20, 20);
scalar = val;
}
Object[] args = imageFirst ? new Object[] { input, scalar, output } : new Object[] { scalar, input, output };
m.invoke(null, args);
GImageMultiBand a = FactoryGImageMultiBand.wrap(input);
GImageMultiBand b = FactoryGImageMultiBand.wrap(output);
float tol = input.getImageType().getDataType().isInteger() ? 1 : 1e-4f;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
a.get(j, i, pixelA);
b.get(j, i, pixelB);
for (int k = 0; k < numBands; k++) {
if (imageFirst)
assertEquals(pixelA[k] - val, pixelB[k], tol);
else
assertEquals(i + " " + j + " " + k, val - pixelA[k], pixelB[k], tol);
}
}
}
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestPixelMath method testMultiply.
private void testMultiply(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageBase input = GeneralizedImageOps.createImage(paramTypes[0], width, height, numBands);
ImageBase output = GeneralizedImageOps.createImage(paramTypes[2], 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, 2, output);
else
m.invoke(null, input, 2.0f, output);
GImageMultiBand a = FactoryGImageMultiBand.wrap(input);
GImageMultiBand b = FactoryGImageMultiBand.wrap(output);
double tol = input.getImageType().getDataType().isInteger() ? 1 : 1e-4;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
a.get(j, i, pixelA);
b.get(j, i, pixelB);
for (int k = 0; k < numBands; k++) {
assertEquals(pixelA[k] * 2, pixelB[k], tol);
}
}
}
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestPixelMath method testPlusBounded.
private void testPlusBounded(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageBase input = GeneralizedImageOps.createImage(paramTypes[0], width, height, numBands);
ImageBase output = GeneralizedImageOps.createImage(paramTypes[0], width, height, numBands);
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, 2, -10, 12, output);
else
m.invoke(null, input, 2.0f, -10f, 12f, output);
GImageMultiBand a = FactoryGImageMultiBand.wrap(input);
GImageMultiBand b = FactoryGImageMultiBand.wrap(output);
float tol = input.getImageType().getDataType().isInteger() ? 1 : 1e-4f;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
a.get(j, i, pixelA);
b.get(j, i, pixelB);
for (int k = 0; k < numBands; k++) {
float expected = pixelA[k] + 2;
float found = pixelB[k];
if (expected < -10)
expected = -10;
if (expected > 12)
expected = 12;
assertEquals(i + " " + j + " " + k, expected, found, tol);
}
}
}
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestPixelMath method testDivide.
private void testDivide(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageBase input = GeneralizedImageOps.createImage(paramTypes[0], width, height, numBands);
ImageBase output = GeneralizedImageOps.createImage(paramTypes[2], width, height, numBands);
int numBands = input.getImageType().getNumBands();
GImageMiscOps.fillUniform(input, rand, 0, 20);
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, output);
else
m.invoke(null, input, 10.0f, output);
double tol = input.getImageType().getDataType().isInteger() ? 1 : 1e-4;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
for (int k = 0; k < numBands; k++) {
double valA = GeneralizedImageOps.get(input, j, i, k);
double valB = GeneralizedImageOps.get(output, j, i, k);
assertEquals(valA / 10.0, valB, tol);
}
}
}
}
Aggregations