use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImageMiscOps method testInsertBand.
private void testInsertBand(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageGray input = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
ImageInterleaved output = GeneralizedImageOps.createInterleaved(paramTypes[2], width, height, numBands);
GImageMiscOps.fillUniform(input, rand, 0, 20);
for (int band = 0; band < numBands; band++) {
GImageMiscOps.fillUniform(output, rand, 0, 20);
m.invoke(null, input, band, output);
int numMatch = 0;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
double valueIn = GeneralizedImageOps.get(input, j, i);
for (int k = 0; k < numBands; k++) {
double valueOut = GeneralizedImageOps.get(output, j, i, k);
if (k == band) {
assertEquals(valueIn, valueOut, 1e-4);
} else {
if (valueIn == valueOut)
numMatch++;
}
}
}
}
assertFalse(numMatch > width * height * (numBands - 1) / 5);
}
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImageMiscOps method testRotateCCW_two.
public void testRotateCCW_two(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageGray a = GeneralizedImageOps.createSingleBand(paramTypes[0], 3, 2);
ImageGray b = GeneralizedImageOps.createSingleBand(paramTypes[0], 2, 3);
for (int i = 0; i < 6; i++) {
GeneralizedImageOps.set(a, i % 3, i / 3, i);
}
m.invoke(null, a, b);
assertEquals(2, GeneralizedImageOps.get(b, 0, 0), 1e-8);
assertEquals(5, GeneralizedImageOps.get(b, 1, 0), 1e-8);
assertEquals(1, GeneralizedImageOps.get(b, 0, 1), 1e-8);
assertEquals(4, GeneralizedImageOps.get(b, 1, 1), 1e-8);
assertEquals(0, GeneralizedImageOps.get(b, 0, 2), 1e-8);
assertEquals(3, GeneralizedImageOps.get(b, 1, 2), 1e-8);
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImageMiscOps method testFill_Single.
private void testFill_Single(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageGray orig = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
GImageMiscOps.fillUniform(orig, rand, 0, 20);
if (orig.getDataType().isInteger()) {
m.invoke(null, orig, 10);
} else {
m.invoke(null, orig, 10.0f);
}
GImageGray a = FactoryGImageGray.wrap(orig);
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
assertEquals(10.0, a.get(j, i).doubleValue(), 1e-4);
}
}
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImageMiscOps method testRotateCW_two.
public void testRotateCW_two(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageGray a = GeneralizedImageOps.createSingleBand(paramTypes[0], 3, 2);
ImageGray b = GeneralizedImageOps.createSingleBand(paramTypes[0], 2, 3);
for (int i = 0; i < 6; i++) {
GeneralizedImageOps.set(a, i % 3, i / 3, i);
}
m.invoke(null, a, b);
assertEquals(3, GeneralizedImageOps.get(b, 0, 0), 1e-8);
assertEquals(0, GeneralizedImageOps.get(b, 1, 0), 1e-8);
assertEquals(4, GeneralizedImageOps.get(b, 0, 1), 1e-8);
assertEquals(1, GeneralizedImageOps.get(b, 1, 1), 1e-8);
assertEquals(5, GeneralizedImageOps.get(b, 0, 2), 1e-8);
assertEquals(2, GeneralizedImageOps.get(b, 1, 2), 1e-8);
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImageStatistics method testHistogram.
private void testHistogram(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageGray inputA = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
int[] histogram = new int[40];
// it should be zeroed
for (int i = 0; i < histogram.length; i++) histogram[i] = 100;
int minValue;
if (inputA.getDataType().isSigned()) {
minValue = -20;
GImageMiscOps.fillUniform(inputA, rand, minValue, 19);
m.invoke(null, inputA, minValue, histogram);
} else {
minValue = 5;
GImageMiscOps.fillUniform(inputA, rand, minValue, minValue + histogram.length - 1);
m.invoke(null, inputA, minValue, histogram);
}
// manually compute the histogram
int[] expected = new int[histogram.length];
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
double a = GeneralizedImageOps.get(inputA, j, i);
expected[(int) (-minValue + a)]++;
}
}
for (int i = 0; i < 40; i++) {
assertEquals("index " + i, expected[i], histogram[i]);
}
}
Aggregations