Search in sources :

Example 1 with Kernel2D_S32

use of boofcv.struct.convolve.Kernel2D_S32 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 2 with Kernel2D_S32

use of boofcv.struct.convolve.Kernel2D_S32 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 3 with Kernel2D_S32

use of boofcv.struct.convolve.Kernel2D_S32 in project BoofCV by lessthanoptimal.

the class TestConvolveNormalizedNaive_IL method convolve.

/**
 * Check it against one specific type to see if the core algorithm is correct
 */
@Test
public void convolve() {
    Kernel2D_S32 kernel = FactoryKernel.random2D_I32(7, 3, 0, 20, rand);
    kernel.offset = 1;
    InterleavedU8 input = new InterleavedU8(width, height, numBands);
    ImageMiscOps.fillUniform(input, rand, 0, 50);
    InterleavedU8 output = new InterleavedU8(width, height, numBands);
    ConvolveNormalizedNaive_IL.convolve(kernel, input, output);
    for (int y = 0; y < output.height; y++) {
        for (int x = 0; x < output.width; x++) {
            for (int band = 0; band < numBands; band++) {
                int expected = convolve(x, y, band, kernel, input);
                int found = output.getBand(x, y, band);
                assertEquals(x + "  " + y, expected, found);
            }
        }
    }
}
Also used : InterleavedU8(boofcv.struct.image.InterleavedU8) Kernel2D_S32(boofcv.struct.convolve.Kernel2D_S32) Test(org.junit.Test)

Example 4 with Kernel2D_S32

use of boofcv.struct.convolve.Kernel2D_S32 in project BoofCV by lessthanoptimal.

the class TestSteerableKernel_I32 method checkCombining.

/**
 * Checks to see if the basis kernels are correctly combined together.
 */
@Test
public void checkCombining() {
    double[] c = new double[] { 0.1, 0.2, 0.8 };
    DummySteerableCoefficients coef = new DummySteerableCoefficients(c);
    Kernel2D[] basis = new Kernel2D[3];
    basis[0] = FactoryKernel.random2D_I32(width, width / 2, 0, 30, rand);
    basis[1] = FactoryKernel.random2D_I32(width, width / 2, 0, 30, rand);
    basis[2] = FactoryKernel.random2D_I32(width, width / 2, 0, 30, rand);
    Kernel2D_S32 expected = new Kernel2D_S32(width);
    for (int y = 0; y < width; y++) {
        for (int x = 0; x < width; x++) {
            int total = 0;
            for (int i = 0; i < c.length; i++) {
                total += c[i] * ((Kernel2D_S32) basis[i]).get(x, y);
            }
            expected.set(x, y, total);
        }
    }
    SteerableKernel_I32 alg = new SteerableKernel_I32();
    alg.setBasis(coef, basis);
    Kernel2D_S32 found = alg.compute(60.0);
    assertTrue(KernelMath.isEquals(expected.data, found.data, width * width));
}
Also used : Kernel2D_S32(boofcv.struct.convolve.Kernel2D_S32) Kernel2D(boofcv.struct.convolve.Kernel2D) Test(org.junit.Test)

Example 5 with Kernel2D_S32

use of boofcv.struct.convolve.Kernel2D_S32 in project BoofCV by lessthanoptimal.

the class ExampleConvolution method normalize2D.

/**
 * Convolves a 2D normalized kernel.  This kernel is divided by its sum after computation.
 */
private static void normalize2D(GrayU8 gray) {
    // Create a Gaussian kernel with radius of 3
    Kernel2D_S32 kernel = FactoryKernelGaussian.gaussian2D(GrayU8.class, -1, 3);
    // Note that there is a more efficient way to compute this convolution since it is a separable kernel
    // just use BlurImageOps instead.
    // Since it's normalized it can be saved inside an 8bit image
    GrayU8 output = new GrayU8(gray.width, gray.height);
    GConvolveImageOps.convolveNormalized(kernel, gray, output);
    panel.addImage(VisualizeImageData.standard(output, null), "2D Normalized Kernel");
}
Also used : Kernel2D_S32(boofcv.struct.convolve.Kernel2D_S32) GrayU8(boofcv.struct.image.GrayU8)

Aggregations

Kernel2D_S32 (boofcv.struct.convolve.Kernel2D_S32)11 GrayU8 (boofcv.struct.image.GrayU8)5 Test (org.junit.Test)5 IntegralKernel (boofcv.alg.transform.ii.IntegralKernel)2 FactoryGImageGray (boofcv.core.image.FactoryGImageGray)2 GImageGray (boofcv.core.image.GImageGray)2 ImageBorder_S32 (boofcv.core.image.border.ImageBorder_S32)2 ImageRectangle (boofcv.struct.ImageRectangle)2 GrayS32 (boofcv.struct.image.GrayS32)2 ImageGray (boofcv.struct.image.ImageGray)2 FilterImageInterface (boofcv.abst.filter.FilterImageInterface)1 BorderIndex1D_Extend (boofcv.core.image.border.BorderIndex1D_Extend)1 ImageBorder1D_S32 (boofcv.core.image.border.ImageBorder1D_S32)1 Kernel2D (boofcv.struct.convolve.Kernel2D)1 GrayS16 (boofcv.struct.image.GrayS16)1 InterleavedU8 (boofcv.struct.image.InterleavedU8)1