use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class CompareToStandardConvolution method createInputParam.
@Override
protected Object[][] createInputParam(Method candidate, Method validation) {
Class<?>[] paramTypes = candidate.getParameterTypes();
ImageBase src = ConvolutionTestHelper.createImage(paramTypes[1], width, height);
GImageMiscOps.fillUniform(src, rand, 0, 130);
ImageBase dst = ConvolutionTestHelper.createImage(paramTypes[2], width, height);
if (candidate.getName().compareTo("convolve") != 0) {
Object[][] ret = new Object[1][paramTypes.length];
ret[0][0] = createKernel(paramTypes[0]);
ret[0][1] = src;
ret[0][2] = dst;
if (paramTypes.length == 4) {
ret[0][3] = 11;
}
return ret;
} else {
Object[][] ret = new Object[1][paramTypes.length];
ret[0][0] = createKernel(paramTypes[0]);
ret[0][1] = src;
ret[0][2] = dst;
if (paramTypes.length == 4) {
ret[0][3] = 11;
}
return ret;
}
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestConvolveImage method compareResults.
@Override
protected void compareResults(Object targetResult, Object[] targetParam, Object validationResult, Object[] validationParam) {
ImageBase targetOut = (ImageBase) targetParam[2];
ImageBase validationOut = (ImageBase) validationParam[2];
// remove the border
computeBorder((KernelBase) targetParam[0], methodTest.getName());
validationOut = stripBorder(validationOut, borderX0, borderY0, borderX1, borderY1);
GImageMultiBand t = FactoryGImageMultiBand.wrap(targetOut);
GImageMultiBand v = FactoryGImageMultiBand.wrap(validationOut);
float[] valueT = new float[t.getNumberOfBands()];
float[] valueV = new float[v.getNumberOfBands()];
for (int y = 0; y < targetOut.height; y++) {
for (int x = 0; x < targetOut.width; x++) {
t.get(x, y, valueT);
v.get(x, y, valueV);
for (int band = 0; band < valueT.length; band++) {
assertEquals("Failed at " + x + " " + y + " band " + band, valueV[band], valueT[band], 1e-4f);
}
}
}
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestClipAndReduce method clipInput.
public void clipInput(ImageType type, int inW, int inH, int outW, int outH) {
ImageBase input = type.createImage(inW, inH);
GImageMiscOps.fillUniform(input, rand, -1, 1);
ClipAndReduce alg = new ClipAndReduce(true, type);
ImageBase output = type.createImage(outW, outH);
GImageMiscOps.fillUniform(output, rand, -1, 1);
ImageBase found = alg.clipInput(input, output);
double foundAspect = found.width / (double) found.height;
double expectedAspect = output.width / (double) output.height;
// won't be perfect
assertEquals(expectedAspect, foundAspect, 0.05);
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestImageStatistics method testMeanDiffSq.
private void testMeanDiffSq(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, 19);
GImageMiscOps.fillUniform(inputB, rand, -20, 19);
} else {
GImageMiscOps.fillUniform(inputA, rand, 0, 19);
GImageMiscOps.fillUniform(inputB, rand, 0, 19);
}
Object result = m.invoke(null, inputA, inputB);
double total = 0;
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);
total += (a - b) * (a - b);
}
}
}
double expected = total / (width * height * numBands);
assertEquals(expected, ((Number) result).doubleValue(), 1e-4);
}
use of boofcv.struct.image.ImageBase in project BoofCV by lessthanoptimal.
the class TestImageStatistics method testMean.
private void testMean(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);
}
}
}
expected /= (width * height * numBands);
double found = ((Number) result).doubleValue();
assertEquals(expected, found, 1e-3);
}
Aggregations