use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestPixelMath method testSubtract.
private void testSubtract(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, 40);
GImageMiscOps.fillUniform(inputB, rand, 0, 40);
}
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);
}
}
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestPixelMath method TestAverageBand.
private void TestAverageBand(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
Planar input = new Planar(paramTypes[1], width, height, 3);
ImageGray output = GeneralizedImageOps.createSingleBand(paramTypes[1], width, height);
if (output.getDataType().isSigned()) {
GImageMiscOps.fillUniform(input, rand, -20, 20);
} else {
GImageMiscOps.fillUniform(input, rand, 0, 20);
}
m.invoke(null, input, output);
GImageGray a = FactoryGImageGray.wrap(input.getBand(0));
GImageGray b = FactoryGImageGray.wrap(input.getBand(1));
GImageGray c = FactoryGImageGray.wrap(input.getBand(2));
GImageGray d = FactoryGImageGray.wrap(output);
boolean isInteger = output.getDataType().isInteger();
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
double expected = 0;
expected += a.get(j, i).doubleValue();
expected += b.get(j, i).doubleValue();
expected += c.get(j, i).doubleValue();
expected /= 3;
double found = d.get(j, i).doubleValue();
if (isInteger)
expected = (int) expected;
assertEquals(expected, found, 1e-4);
}
}
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class PermuteWaveletCompare method runTest.
private void runTest(int widthIn, int heightIn, int widthOut, int heightOut, boolean swapSize) {
if (swapSize) {
int t = widthIn;
widthIn = widthOut;
widthOut = t;
t = heightIn;
heightIn = heightOut;
heightOut = t;
}
ImageGray input = GeneralizedImageOps.createSingleBand(inputType, widthIn, heightIn);
ImageGray found = GeneralizedImageOps.createSingleBand(outputType, widthOut, heightOut);
ImageGray expected = GeneralizedImageOps.createSingleBand(outputType, widthOut, heightOut);
GImageMiscOps.fillUniform(input, rand, 0, 50);
// test different descriptions lengths and offsets, and borders
for (BorderType type : BorderType.values()) {
for (int o = 0; o <= 2; o++) {
for (int l = 2 + o; l <= 5; l++) {
// System.out.println("type "+type+" o = "+o+" l = "+l);
GImageMiscOps.fill(found, 0);
GImageMiscOps.fill(expected, 0);
// create a random wavelet. does not have to be a real once
// since it just is checking that two functions produce the same output
WaveletDescription<?> desc = createDesc(-o, l, type);
applyValidation(desc, input, expected);
// make sure it works on sub-images
BoofTesting.checkSubImage(this, "innerTest", false, input, found, expected, desc);
}
}
}
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImplIntegralImageOps method convolveSparse.
public void convolveSparse(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramType = m.getParameterTypes();
Class inputType = paramType[0];
ImageGray integral = GeneralizedImageOps.createSingleBand(inputType, width, height);
GImageMiscOps.fillUniform(integral, rand, 0, 1000);
ImageGray expected = GeneralizedImageOps.createSingleBand(inputType, width, height);
IntegralKernel kernel = new IntegralKernel(2);
kernel.blocks[0] = new ImageRectangle(-2, -2, 1, 1);
kernel.blocks[1] = new ImageRectangle(-2, -1, 1, 0);
kernel.scales = new int[] { 1, 2 };
GIntegralImageOps.convolve(integral, kernel, expected);
GImageGray e = FactoryGImageGray.wrap(expected);
double found0 = ((Number) m.invoke(null, integral, kernel, 0, 0)).doubleValue();
double found1 = ((Number) m.invoke(null, integral, kernel, 10, 12)).doubleValue();
double found2 = ((Number) m.invoke(null, integral, kernel, 19, 29)).doubleValue();
assertEquals(e.get(0, 0).doubleValue(), found0, 1e-4f);
assertEquals(e.get(10, 12).doubleValue(), found1, 1e-4f);
assertEquals(e.get(19, 29).doubleValue(), found2, 1e-4f);
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImplIntegralImageOps method block_zero.
public void block_zero(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramType = m.getParameterTypes();
Class inputType = paramType[0];
Class origType = inputType == GrayS32.class ? GrayU8.class : inputType;
ImageGray input = GeneralizedImageOps.createSingleBand(origType, width, height);
ImageGray integral = GeneralizedImageOps.createSingleBand(inputType, width, height);
GImageMiscOps.fill(input, 1);
GIntegralImageOps.transform(input, integral);
double found = ((Number) m.invoke(null, integral, 4, 5, 8, 8)).doubleValue();
assertEquals(12, found, 1e-4f);
found = ((Number) m.invoke(null, integral, -1, -2, 2, 3)).doubleValue();
assertEquals(12, found, 1e-4f);
found = ((Number) m.invoke(null, integral, width - 2, height - 3, width + 1, height + 3)).doubleValue();
assertEquals(2, found, 1e-4f);
found = ((Number) m.invoke(null, integral, 3, -4, -1, -1)).doubleValue();
assertEquals(0, found, 1e-4f);
found = ((Number) m.invoke(null, integral, width + 1, height + 2, width + 6, height + 8)).doubleValue();
assertEquals(0, found, 1e-4f);
}
Aggregations