Search in sources :

Example 36 with ImageGray

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);
}
Also used : Kernel2D_S32(boofcv.struct.convolve.Kernel2D_S32) IntegralKernel(boofcv.alg.transform.ii.IntegralKernel) ImageRectangle(boofcv.struct.ImageRectangle) GrayU8(boofcv.struct.image.GrayU8) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray) ImageBorder_S32(boofcv.core.image.border.ImageBorder_S32) GrayS32(boofcv.struct.image.GrayS32)

Example 37 with ImageGray

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);
}
Also used : Kernel2D_S32(boofcv.struct.convolve.Kernel2D_S32) IntegralKernel(boofcv.alg.transform.ii.IntegralKernel) ImageRectangle(boofcv.struct.ImageRectangle) GrayU8(boofcv.struct.image.GrayU8) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray) ImageBorder_S32(boofcv.core.image.border.ImageBorder_S32) GrayS32(boofcv.struct.image.GrayS32)

Example 38 with ImageGray

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);
    }
}
Also used : Bitmap(android.graphics.Bitmap) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray)

Example 39 with ImageGray

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);
    }
}
Also used : Bitmap(android.graphics.Bitmap) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray)

Example 40 with ImageGray

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);
}
Also used : Kernel1D_S32(boofcv.struct.convolve.Kernel1D_S32) GrayF32(boofcv.struct.image.GrayF32) Kernel1D_F32(boofcv.struct.convolve.Kernel1D_F32) GrayU8(boofcv.struct.image.GrayU8) ImageGray(boofcv.struct.image.ImageGray)

Aggregations

ImageGray (boofcv.struct.image.ImageGray)110 FactoryGImageGray (boofcv.core.image.FactoryGImageGray)43 GImageGray (boofcv.core.image.GImageGray)43 Test (org.junit.Test)26 GrayF32 (boofcv.struct.image.GrayF32)20 Method (java.lang.reflect.Method)17 GrayU8 (boofcv.struct.image.GrayU8)15 Bitmap (android.graphics.Bitmap)4 ImageBorder_S32 (boofcv.core.image.border.ImageBorder_S32)4 GrayS16 (boofcv.struct.image.GrayS16)4 GrayS32 (boofcv.struct.image.GrayS32)4 Planar (boofcv.struct.image.Planar)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 IntegralKernel (boofcv.alg.transform.ii.IntegralKernel)3 ImageRectangle (boofcv.struct.ImageRectangle)3 FDistort (boofcv.abst.distort.FDistort)2 ImageBorder_F32 (boofcv.core.image.border.ImageBorder_F32)2 FactoryDescribeImageDense (boofcv.factory.feature.dense.FactoryDescribeImageDense)2 Kernel2D_S32 (boofcv.struct.convolve.Kernel2D_S32)2 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)2