use of boofcv.core.image.GImageGray in project BoofCV by lessthanoptimal.
the class TestImageMiscOps method testAddGaussian_Single.
private void testAddGaussian_Single(Method m) throws InvocationTargetException, IllegalAccessException {
double mean = 10;
Class[] paramTypes = m.getParameterTypes();
ImageGray orig = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
GImageMiscOps.fill(orig, mean);
m.invoke(null, orig, rand, 2.0, 0, 255);
double stdev2 = 0;
GImageGray a = FactoryGImageGray.wrap(orig);
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
double value = a.get(j, i).doubleValue();
stdev2 += (value - mean) * (value - mean);
}
}
GImageMiscOps.fill(orig, mean);
m.invoke(null, orig, rand, 10.0, 0, 255);
double stdev10 = 0;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
double value = a.get(j, i).doubleValue();
stdev10 += (value - mean) * (value - mean);
}
}
// see if the gaussian with the larger variance creates a noisier image
assertTrue(stdev2 < stdev10);
}
use of boofcv.core.image.GImageGray in project BoofCV by lessthanoptimal.
the class TestImageMiscOps method testFillGaussian_Single.
private void testFillGaussian_Single(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageGray orig = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
if (orig.getDataType().isSigned())
m.invoke(null, orig, rand, 0, 5, -2, 2);
else {
m.invoke(null, orig, rand, 5, 7, 0, 12);
}
int numZero = 0;
GImageGray a = FactoryGImageGray.wrap(orig);
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
double value = a.get(j, i).doubleValue();
if (orig.getDataType().isSigned()) {
assertTrue("value = " + value, value >= -2 && value <= 2);
} else {
assertTrue("value = " + value, value >= 0 && value <= 12);
}
if (value == 0)
numZero++;
}
}
assertTrue(numZero < width * height);
}
use of boofcv.core.image.GImageGray in project BoofCV by lessthanoptimal.
the class TestImageMiscOps method testAddUniform_Single.
private void testAddUniform_Single(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramTypes = m.getParameterTypes();
ImageGray orig = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
GImageMiscOps.fill(orig, 1);
if (orig.getDataType().isInteger()) {
m.invoke(null, orig, rand, 1, 10);
} else {
m.invoke(null, orig, rand, 1, 10);
}
GImageGray a = FactoryGImageGray.wrap(orig);
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
double value = a.get(j, i).doubleValue();
assertTrue(value >= -2 && value <= 11);
}
}
}
use of boofcv.core.image.GImageGray in project BoofCV by lessthanoptimal.
the class TestImplConvertBitmap method checkArrayToGray.
public void checkArrayToGray(Method m, Bitmap.Config config) {
Bitmap orig = Bitmap.createBitmap(w, h, config);
orig.setPixel(1, 2, 0xFF204010);
Class[] params = m.getParameterTypes();
try {
ImageGray found = (ImageGray) params[2].getConstructor(int.class, int.class).newInstance(w, h);
Object array;
String info = params[2].getSimpleName();
if (params[0] == int[].class) {
info += " Array32";
orig.copyPixelsToBuffer(IntBuffer.wrap(buffer32));
array = buffer32;
} else {
info += " Array8";
orig.copyPixelsToBuffer(ByteBuffer.wrap(buffer8));
array = buffer8;
}
info += " " + config;
m.invoke(null, array, config, found);
GImageGray g = FactoryGImageGray.wrap(found);
// should be 37 for both 8888 and 565
assertEquals(info, 37, g.get(1, 2).intValue());
assertEquals(info, 0, g.get(0, 0).intValue());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of boofcv.core.image.GImageGray in project BoofCV by lessthanoptimal.
the class TestImplConvertBitmap method checkBitmapToGrayRGB.
public void checkBitmapToGrayRGB(Method m, Bitmap.Config config) {
Bitmap orig = Bitmap.createBitmap(w, h, config);
orig.setPixel(1, 2, 0xFF204010);
Class[] params = m.getParameterTypes();
String info = config + " " + params[1].getSimpleName();
try {
ImageGray found = (ImageGray) params[1].getConstructor(int.class, int.class).newInstance(w, h);
m.invoke(null, orig, found);
GImageGray g = FactoryGImageGray.wrap(found);
// should be 37 for both 8888 and 565
assertEquals(info, 37, g.get(1, 2).intValue());
assertEquals(info, 0, g.get(0, 0).intValue());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations