use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImplAverageDownSample method horizontal_3_to_2.
/**
* The division will not be along pixels and symmetries are avoided
*/
@Test
public void horizontal_3_to_2() throws InvocationTargetException, IllegalAccessException {
List<Method> methods = find("horizontal");
for (Method m : methods) {
Class typeSrc = m.getParameterTypes()[0];
Class typeDst = m.getParameterTypes()[1];
// System.out.println(typeSrc+" "+typeDst);
ImageGray src = GeneralizedImageOps.createSingleBand(typeSrc, 9, 3);
ImageGray dst = GeneralizedImageOps.createSingleBand(typeDst, 4, 3);
fillHorizontal(src);
m.invoke(null, src, dst);
for (int y = 0; y < src.height; y++) {
assertEquals(0.6666667f, GeneralizedImageOps.get(dst, 0, y), 1e-4f);
assertEquals(2.8888889f, GeneralizedImageOps.get(dst, 1, y), 1e-4f);
assertEquals(5.1111111f, GeneralizedImageOps.get(dst, 2, y), 1e-4f);
assertEquals(7.3333333f, GeneralizedImageOps.get(dst, 3, y), 1e-4f);
}
}
assertEquals(4, methods.size());
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImplAverageDownSample method vertical_3_to_2.
@Test
public void vertical_3_to_2() 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, 9);
ImageGray dst = GeneralizedImageOps.createSingleBand(typeDst, 3, 4);
fillVertical(src);
m.invoke(null, src, dst);
double[] expected;
if (dst.getDataType().isInteger()) {
expected = new double[] { 1, 3, 5, 7 };
} else {
expected = new double[] { 0.6666667f, 2.8888889f, 5.1111111f, 7.3333333f };
}
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());
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImplAverageDownSample2 method compareToNaive.
public void compareToNaive(Method m) {
Class inputType = m.getParameterTypes()[0];
Class outputType = m.getParameterTypes()[1];
ImageGray input = GeneralizedImageOps.createSingleBand(inputType, width, height);
GImageMiscOps.fillUniform(input, rand, 0, 100);
int downWidth = AverageDownSampleOps.downSampleSize(width, 2);
int downHeight = AverageDownSampleOps.downSampleSize(height, 2);
ImageGray found = GeneralizedImageOps.createSingleBand(outputType, downWidth, downHeight);
ImageGray expected = GeneralizedImageOps.createSingleBand(outputType, downWidth, downHeight);
try {
m.invoke(null, input, found);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
naive(input, 2, expected);
BoofTesting.assertEquals(found, expected, 1e-4);
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImplAverageDownSampleN method compareToNaive.
public void compareToNaive(Method m) {
Class inputType = m.getParameterTypes()[0];
Class outputType = m.getParameterTypes()[2];
ImageGray input = GeneralizedImageOps.createSingleBand(inputType, width, height);
GImageMiscOps.fillUniform(input, rand, 0, 100);
for (int region = 1; region <= 5; region++) {
int downWidth = width % region == 0 ? width / region : width / region + 1;
int downHeight = height % region == 0 ? height / region : height / region + 1;
ImageGray found = GeneralizedImageOps.createSingleBand(outputType, downWidth, downHeight);
ImageGray expected = GeneralizedImageOps.createSingleBand(outputType, downWidth, downHeight);
try {
m.invoke(null, input, region, found);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
naive(input, region, expected);
BoofTesting.assertEquals(found, expected, 1e-4);
}
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestConvolveImageStandard_SB method testMethod.
/**
* Using the method's name and the number of parameters invoke the appropriate test function
*/
private void testMethod(Method m) {
Class[] param = m.getParameterTypes();
ImageGray input = GeneralizedImageOps.createSingleBand(param[1], width, height);
ImageGray output = GeneralizedImageOps.createSingleBand(param[2], width, height);
GImageMiscOps.fillUniform(input, rand, 1, maxPixelValue);
if (m.getName().contentEquals("horizontal")) {
if (param.length == 3) {
BoofTesting.checkSubImage(this, "horizontal", true, input, output);
} else {
BoofTesting.checkSubImage(this, "horizontalDiv", true, input, output);
}
} else if (m.getName().contentEquals("vertical")) {
if (param.length == 3) {
BoofTesting.checkSubImage(this, "vertical", true, input, output);
} else {
BoofTesting.checkSubImage(this, "verticalDiv", true, input, output);
}
} else if (m.getName().contentEquals("convolve")) {
if (param.length == 3) {
BoofTesting.checkSubImage(this, "convolve", true, input, output);
} else {
BoofTesting.checkSubImage(this, "convolveDiv", true, input, output);
}
} else {
fail("Unknown method name: " + m.getName());
}
}
Aggregations