use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImplIntegralImageOps method convolve.
public void convolve(Method m) throws InvocationTargetException, IllegalAccessException {
Kernel2D_S32 kernel = new Kernel2D_S32(3, new int[] { 1, 1, 1, 2, 2, 2, 1, 1, 1 });
GrayU8 input = new GrayU8(width, height);
GrayS32 expected = new GrayS32(width, height);
GImageMiscOps.fillUniform(input, rand, 0, 10);
ImageBorder_S32 border = FactoryImageBorderAlgs.value(input, 0);
ConvolveImage.convolve(kernel, input, expected, border);
Class[] paramType = m.getParameterTypes();
Class inputType = paramType[0];
Class outputType = paramType[2];
ImageGray inputII = GeneralizedImageOps.createSingleBand(inputType, width, height);
ImageGray integral = GeneralizedImageOps.createSingleBand(outputType, width, height);
ImageGray expectedII = GeneralizedImageOps.createSingleBand(outputType, width, height);
ImageGray found = GeneralizedImageOps.createSingleBand(outputType, width, height);
GConvertImage.convert(input, inputII);
GConvertImage.convert(expected, expectedII);
GIntegralImageOps.transform(inputII, integral);
IntegralKernel kernelII = new IntegralKernel(2);
kernelII.blocks[0] = new ImageRectangle(-2, -2, 1, 1);
kernelII.blocks[1] = new ImageRectangle(-2, -1, 1, 0);
kernelII.scales = new int[] { 1, 1 };
m.invoke(null, integral, kernelII, found);
BoofTesting.assertEqualsRelative(expected, found, 1e-4f);
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImplIntegralImageOps method convolveBorder.
public void convolveBorder(Method m) throws InvocationTargetException, IllegalAccessException {
Kernel2D_S32 kernel = new Kernel2D_S32(3, new int[] { 1, 1, 1, 2, 2, 2, 1, 1, 1 });
GrayU8 input = new GrayU8(width, height);
GrayS32 expected = new GrayS32(width, height);
GImageMiscOps.fillUniform(input, rand, 0, 10);
ImageBorder_S32 border = FactoryImageBorderAlgs.value(input, 0);
ConvolveImage.convolve(kernel, input, expected, border);
Class[] paramType = m.getParameterTypes();
Class inputType = paramType[0];
Class outputType = paramType[2];
ImageGray inputII = GeneralizedImageOps.createSingleBand(inputType, width, height);
ImageGray integral = GeneralizedImageOps.createSingleBand(outputType, width, height);
ImageGray expectedII = GeneralizedImageOps.createSingleBand(outputType, width, height);
ImageGray found = GeneralizedImageOps.createSingleBand(outputType, width, height);
GConvertImage.convert(input, inputII);
GConvertImage.convert(expected, expectedII);
GIntegralImageOps.transform(inputII, integral);
IntegralKernel kernelII = new IntegralKernel(2);
kernelII.blocks[0] = new ImageRectangle(-2, -2, 1, 1);
kernelII.blocks[1] = new ImageRectangle(-2, -1, 1, 0);
kernelII.scales = new int[] { 1, 1 };
m.invoke(null, integral, kernelII, found, 4, 5);
BoofTesting.assertEqualsBorder(expected, found, 1e-4f, 4, 5);
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImplConvertBitmap method checkGrayToArray.
public void checkGrayToArray(Method m, Bitmap.Config config) {
Bitmap dst = Bitmap.createBitmap(w, h, config);
Class[] params = m.getParameterTypes();
try {
ImageGray src = (ImageGray) params[0].getConstructor(int.class, int.class).newInstance(w, h);
GeneralizedImageOps.set(src, 1, 2, 16);
GeneralizedImageOps.set(src, 1, 3, 0xFF);
Object array;
String info = params[0].getSimpleName();
if (params[2] == int[].class) {
info += " Array32";
array = buffer32;
} else {
info += " Array8";
array = buffer8;
}
info += " " + config;
m.invoke(null, src, array, config);
if (params[2] == int[].class) {
dst.copyPixelsFromBuffer(IntBuffer.wrap(buffer32));
} else {
dst.copyPixelsFromBuffer(ByteBuffer.wrap(buffer8));
}
GImageGray g = FactoryGImageGray.wrap(src);
if (config == Bitmap.Config.ARGB_8888) {
assertEquals(info, 0xFF101010, (int) dst.getPixel(1, 2));
assertEquals(info, 0xFFFFFFFF, (int) dst.getPixel(1, 3));
} else {
assertEquals(info, expected565(16, 16, 16), (int) dst.getPixel(1, 2));
assertEquals(info, expected565(255, 255, 255), (int) dst.getPixel(1, 3));
}
assertEquals(info, 0xFF000000, dst.getPixel(0, 0));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestImplConvertBitmap method checkGrayToBitmapRGB.
public void checkGrayToBitmapRGB(Method m, Bitmap.Config config) {
Bitmap dst = Bitmap.createBitmap(w, h, config);
Class[] params = m.getParameterTypes();
try {
ImageGray src = (ImageGray) params[0].getConstructor(int.class, int.class).newInstance(w, h);
GeneralizedImageOps.set(src, 1, 2, 16);
GeneralizedImageOps.set(src, 1, 3, 0xFF);
String info = config + " " + params[0].getSimpleName();
m.invoke(null, src, dst);
assertEquals(info, 0xFF101010, (int) dst.getPixel(1, 2));
assertEquals(info, 0xFFFFFFFF, (int) dst.getPixel(1, 3));
assertEquals(info, 0xFF000000, dst.getPixel(0, 0));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of boofcv.struct.image.ImageGray in project BoofCV by lessthanoptimal.
the class TestConvolveImageStandardSparse method checkMethod.
private void checkMethod(Method method, int width, int height, int kernelOffset, int kernelWidth, Random rand) {
GrayU8 seedImage = new GrayU8(width, height);
ImageMiscOps.fillUniform(seedImage, rand, 0, 255);
// creates a floating point image with integer elements
GrayF32 floatImage = new GrayF32(width, height);
ConvertImage.convert(seedImage, floatImage);
sumKernel = 0;
kernelI32 = FactoryKernelGaussian.gaussian(Kernel1D_S32.class, -1, kernelWidth / 2);
kernelF32 = new Kernel1D_F32(kernelI32.width);
for (int i = 0; i < kernelI32.width; i++) {
sumKernel += kernelF32.data[i] = kernelI32.data[i];
}
kernelI32.offset = kernelOffset;
kernelF32.offset = kernelOffset;
boolean isFloatingKernel = method.getParameterTypes()[0] == Kernel1D_F32.class;
boolean isDivisor = method.getParameterTypes().length != 6;
expectedOutput = computeExpected(seedImage, !isFloatingKernel, isDivisor);
ImageGray inputImage = GeneralizedImageOps.convert(floatImage, null, (Class) method.getParameterTypes()[2]);
Object inputKernel = isFloatingKernel ? kernelF32 : kernelI32;
Object inputStorage = isFloatingKernel ? new float[kernelI32.width] : new int[kernelI32.width];
checkResults(method, inputKernel, inputImage, inputStorage);
}
Aggregations