use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImplConvolveMean method compareResults.
@Override
protected void compareResults(Object targetResult, Object[] targetParam, Object validationResult, Object[] validationParam) {
ImageGray expected = (ImageGray) validationParam[2];
ImageGray found = (ImageGray) targetParam[1];
BoofTesting.assertEquals(expected, found, 1e-4);
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class CompareDerivativeToConvolution method innerCompare.
protected void innerCompare(ImageGray inputImage, ImageGray... outputImages) {
Class<?>[] param = m.getParameterTypes();
int numImageOutputs = countImageOutputs(param);
if (outputImages.length != numImageOutputs)
throw new RuntimeException("Unexpected number of outputImages passed in");
// declare and compute the validation results
ImageGray[] expectedOutput = new ImageGray[param.length - 2];
for (int i = 0; i < expectedOutput.length; i++) {
expectedOutput[i] = (ImageGray) outputImages[i].createNew(inputImage.width, inputImage.height);
outputFilters[i].process(inputImage, expectedOutput[i]);
}
// compute results from the test function
Object[] testInputs = new Object[param.length];
testInputs[0] = inputImage;
for (int i = 1; i < numImageOutputs + 1; i++) {
testInputs[i] = outputImages[i - 1];
}
if (param.length == numImageOutputs + 2) {
if (processBorder) {
testInputs[param.length - 1] = FactoryImageBorder.single(inputImage.getClass(), BorderType.EXTENDED);
} else {
testInputs[param.length - 1] = null;
}
}
try {
m.invoke(null, testInputs);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
// assume the most extreme border is used
int borderX0 = 0, borderY0 = 0, borderX1 = 0, borderY1 = 0;
for (int i = 0; i < expectedOutput.length; i++) {
Border b = borders[i];
borderX0 = Math.max(borderX0, b.borderX0);
borderX1 = Math.max(borderX1, b.borderX1);
borderY0 = Math.max(borderY0, b.borderY0);
borderY1 = Math.max(borderY1, b.borderY1);
}
// compare the results
for (int i = 0; i < expectedOutput.length; i++) {
BoofTesting.assertEqualsInner(expectedOutput[i], outputImages[i], 1e-4f, borderX0, borderY0, borderX1, borderY1, false);
if (!processBorder)
BoofTesting.checkBorderZero(outputImages[i], borderX0, borderY0, borderX1, borderY1);
}
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class StandardGradientChecks method testSecondDerivative.
/**
* The XY and YX second derivatives should be indential
*/
private void testSecondDerivative(Method m1, Method m2) {
Class[] params = m1.getParameterTypes();
ImageGray input = GeneralizedImageOps.createSingleBand(params[0], width, height);
ImageGray derivX = GeneralizedImageOps.createSingleBand(params[1], width, height);
ImageGray derivY = GeneralizedImageOps.createSingleBand(params[2], width, height);
ImageGray derivXX = GeneralizedImageOps.createSingleBand(params[1], width, height);
ImageGray derivYY = GeneralizedImageOps.createSingleBand(params[2], width, height);
ImageGray derivXY = GeneralizedImageOps.createSingleBand(params[1], width, height);
ImageGray derivYX = GeneralizedImageOps.createSingleBand(params[1], width, height);
GImageMiscOps.fillUniform(input, rand, 0, 40);
Object border;
if (params[3] == ImageBorder_F32.class) {
border = new ImageBorder1D_F32(BorderIndex1D_Wrap.class);
} else {
border = new ImageBorder1D_S32(BorderIndex1D_Wrap.class);
}
try {
m1.invoke(null, input, derivX, derivY, border);
m2.invoke(null, derivX, derivXX, derivXY, border);
m2.invoke(null, derivY, derivYX, derivYY, border);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
// BoofTesting.printDiff(derivXY,derivYX);
BoofTesting.assertEquals(derivXY, derivYX, 1e-3f);
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImplAverageDownSample method vertical_1_to_1.
@Test
public void vertical_1_to_1() throws InvocationTargetException, IllegalAccessException {
List<Method> methods = find("vertical");
for (Method m : methods) {
Class typeSrc = m.getParameterTypes()[0];
Class typeDst = m.getParameterTypes()[1];
ImageGray src = GeneralizedImageOps.createSingleBand(typeSrc, 3, 6);
ImageGray dst = GeneralizedImageOps.createSingleBand(typeDst, 3, 6);
fillVertical(src);
m.invoke(null, src, dst);
for (int y = 0; y < src.height; y++) {
for (int x = 0; x < src.width; x++) {
assertEquals(y, GeneralizedImageOps.get(dst, x, y), 1e-4);
}
}
}
assertEquals(4, methods.size());
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImplAverageDownSample method vertical_2_to_1.
@Test
public void vertical_2_to_1() throws InvocationTargetException, IllegalAccessException {
List<Method> methods = find("vertical");
for (Method m : methods) {
Class typeSrc = m.getParameterTypes()[0];
Class typeDst = m.getParameterTypes()[1];
// System.out.println(typeSrc+" "+typeDst);
ImageGray src = GeneralizedImageOps.createSingleBand(typeSrc, 3, 6);
ImageGray dst = GeneralizedImageOps.createSingleBand(typeDst, 3, 3);
fillVertical(src);
m.invoke(null, src, dst);
double[] expected;
if (dst.getDataType().isInteger()) {
expected = new double[] { 1, 3, 5 };
} else {
expected = new double[] { 0.5, 2.5, 4.5 };
}
for (int x = 0; x < src.width; x++) {
for (int y = 0; y < dst.height; y++) {
assertEquals(expected[y], GeneralizedImageOps.get(dst, x, y), 1e-4);
}
}
}
assertEquals(4, methods.size());
}
Aggregations