Search in sources :

Example 1 with IntegralKernel

use of boofcv.alg.transform.ii.IntegralKernel in project BoofCV by lessthanoptimal.

the class TestImplIntegralImageOps method convolveSparse.

public void convolveSparse(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramType = m.getParameterTypes();
    Class inputType = paramType[0];
    ImageGray integral = GeneralizedImageOps.createSingleBand(inputType, width, height);
    GImageMiscOps.fillUniform(integral, rand, 0, 1000);
    ImageGray expected = GeneralizedImageOps.createSingleBand(inputType, width, height);
    IntegralKernel kernel = new IntegralKernel(2);
    kernel.blocks[0] = new ImageRectangle(-2, -2, 1, 1);
    kernel.blocks[1] = new ImageRectangle(-2, -1, 1, 0);
    kernel.scales = new int[] { 1, 2 };
    GIntegralImageOps.convolve(integral, kernel, expected);
    GImageGray e = FactoryGImageGray.wrap(expected);
    double found0 = ((Number) m.invoke(null, integral, kernel, 0, 0)).doubleValue();
    double found1 = ((Number) m.invoke(null, integral, kernel, 10, 12)).doubleValue();
    double found2 = ((Number) m.invoke(null, integral, kernel, 19, 29)).doubleValue();
    assertEquals(e.get(0, 0).doubleValue(), found0, 1e-4f);
    assertEquals(e.get(10, 12).doubleValue(), found1, 1e-4f);
    assertEquals(e.get(19, 29).doubleValue(), found2, 1e-4f);
}
Also used : IntegralKernel(boofcv.alg.transform.ii.IntegralKernel) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageRectangle(boofcv.struct.ImageRectangle) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray)

Example 2 with IntegralKernel

use of boofcv.alg.transform.ii.IntegralKernel 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 3 with IntegralKernel

use of boofcv.alg.transform.ii.IntegralKernel 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 4 with IntegralKernel

use of boofcv.alg.transform.ii.IntegralKernel in project BoofCV by lessthanoptimal.

the class ImplIntegralImageFeatureIntensity method hessianBorder.

/**
 * Only computes the fast hessian along the border using a brute force approach
 */
public static void hessianBorder(GrayF32 integral, int skip, int size, GrayF32 intensity) {
    final int w = intensity.width;
    final int h = intensity.height;
    // get convolution kernels for the second order derivatives
    IntegralKernel kerXX = DerivativeIntegralImage.kernelDerivXX(size, null);
    IntegralKernel kerYY = DerivativeIntegralImage.kernelDerivYY(size, null);
    IntegralKernel kerXY = DerivativeIntegralImage.kernelDerivXY(size, null);
    int radiusFeature = size / 2;
    final int borderOrig = radiusFeature + 1 + (skip - (radiusFeature + 1) % skip);
    final int border = borderOrig / skip;
    float norm = 1.0f / (size * size);
    for (int y = 0; y < h; y++) {
        int yy = y * skip;
        for (int x = 0; x < border; x++) {
            int xx = x * skip;
            computeHessian(integral, intensity, kerXX, kerYY, kerXY, norm, y, yy, x, xx);
        }
        for (int x = w - border; x < w; x++) {
            int xx = x * skip;
            computeHessian(integral, intensity, kerXX, kerYY, kerXY, norm, y, yy, x, xx);
        }
    }
    for (int x = border; x < w - border; x++) {
        int xx = x * skip;
        for (int y = 0; y < border; y++) {
            int yy = y * skip;
            computeHessian(integral, intensity, kerXX, kerYY, kerXY, norm, y, yy, x, xx);
        }
        for (int y = h - border; y < h; y++) {
            int yy = y * skip;
            computeHessian(integral, intensity, kerXX, kerYY, kerXY, norm, y, yy, x, xx);
        }
    }
}
Also used : IntegralKernel(boofcv.alg.transform.ii.IntegralKernel)

Example 5 with IntegralKernel

use of boofcv.alg.transform.ii.IntegralKernel in project BoofCV by lessthanoptimal.

the class ImplIntegralImageFeatureIntensity method hessianNaive.

/**
 * Brute force approach which is easy to validate through visual inspection.
 */
public static void hessianNaive(GrayS32 integral, int skip, int size, GrayF32 intensity) {
    final int w = intensity.width;
    final int h = intensity.height;
    // get convolution kernels for the second order derivatives
    IntegralKernel kerXX = DerivativeIntegralImage.kernelDerivXX(size, null);
    IntegralKernel kerYY = DerivativeIntegralImage.kernelDerivYY(size, null);
    IntegralKernel kerXY = DerivativeIntegralImage.kernelDerivXY(size, null);
    float norm = 1.0f / (size * size);
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int xx = x * skip;
            int yy = y * skip;
            computeHessian(integral, intensity, kerXX, kerYY, kerXY, norm, y, yy, x, xx);
        }
    }
}
Also used : IntegralKernel(boofcv.alg.transform.ii.IntegralKernel)

Aggregations

IntegralKernel (boofcv.alg.transform.ii.IntegralKernel)7 FactoryGImageGray (boofcv.core.image.FactoryGImageGray)3 GImageGray (boofcv.core.image.GImageGray)3 ImageRectangle (boofcv.struct.ImageRectangle)3 ImageGray (boofcv.struct.image.ImageGray)3 ImageBorder_S32 (boofcv.core.image.border.ImageBorder_S32)2 Kernel2D_S32 (boofcv.struct.convolve.Kernel2D_S32)2 GrayS32 (boofcv.struct.image.GrayS32)2 GrayU8 (boofcv.struct.image.GrayU8)2