Search in sources :

Example 6 with Kernel2D_F32

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

the class TestSteerableKernel_F32 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_F32(width, width / 2, 0, 10, rand);
    basis[1] = FactoryKernel.random2D_F32(width, width / 2, 0, 10, rand);
    basis[2] = FactoryKernel.random2D_F32(width, width / 2, 0, 10, rand);
    Kernel2D_F32 expected = new Kernel2D_F32(width);
    for (int y = 0; y < width; y++) {
        for (int x = 0; x < width; x++) {
            float total = 0;
            for (int i = 0; i < c.length; i++) {
                total += c[i] * ((Kernel2D_F32) basis[i]).get(x, y);
            }
            expected.set(x, y, total);
        }
    }
    SteerableKernel_F32 alg = new SteerableKernel_F32();
    alg.setBasis(coef, basis);
    Kernel2D_F32 found = alg.compute(60.0);
    assertTrue(KernelMath.isEquals(expected.data, found.data, width * width, 1e-4f));
}
Also used : Kernel2D_F32(boofcv.struct.convolve.Kernel2D_F32) Kernel2D(boofcv.struct.convolve.Kernel2D) Test(org.junit.Test)

Example 7 with Kernel2D_F32

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

the class SiftDetector method createSparseDerivatives.

/**
 * Define sparse image derivative operators.
 */
private void createSparseDerivatives() {
    Kernel1D_F32 kernelD = new Kernel1D_F32(new float[] { -1, 0, 1 }, 3);
    Kernel1D_F32 kernelDD = KernelMath.convolve1D_F32(kernelD, kernelD);
    Kernel2D_F32 kernelXY = KernelMath.convolve2D(kernelD, kernelD);
    derivXX = FactoryConvolveSparse.horizontal1D(GrayF32.class, kernelDD);
    derivXY = FactoryConvolveSparse.convolve2D(GrayF32.class, kernelXY);
    derivYY = FactoryConvolveSparse.vertical1D(GrayF32.class, kernelDD);
    ImageBorder<GrayF32> border = FactoryImageBorder.single(GrayF32.class, BorderType.EXTENDED);
    derivXX.setImageBorder(border);
    derivXY.setImageBorder(border);
    derivYY.setImageBorder(border);
}
Also used : Kernel2D_F32(boofcv.struct.convolve.Kernel2D_F32) GrayF32(boofcv.struct.image.GrayF32) Kernel1D_F32(boofcv.struct.convolve.Kernel1D_F32)

Example 8 with Kernel2D_F32

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

the class OrientationImageAverage method setObjectRadius.

@Override
public void setObjectRadius(double objectRadius) {
    sampleRadius = (int) Math.ceil(objectRadius * objectToSample);
    int w = sampleRadius * 2 + 1;
    kerCosine = new Kernel2D_F32(w);
    kerSine = new Kernel2D_F32(w);
    for (int y = -sampleRadius; y <= sampleRadius; y++) {
        int pixelY = y + sampleRadius;
        for (int x = -sampleRadius; x <= sampleRadius; x++) {
            int pixelX = x + sampleRadius;
            float r = (float) Math.sqrt(x * x + y * y);
            kerCosine.set(pixelX, pixelY, (float) x / r);
            kerSine.set(pixelX, pixelY, (float) y / r);
        }
    }
    kerCosine.set(sampleRadius, sampleRadius, 0);
    kerSine.set(sampleRadius, sampleRadius, 0);
}
Also used : Kernel2D_F32(boofcv.struct.convolve.Kernel2D_F32)

Example 9 with Kernel2D_F32

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

the class FactoryDerivativeSparse method createLaplacian.

/**
 * Creates a sparse Laplacian filter.
 *
 * @see boofcv.alg.filter.derivative.LaplacianEdge
 *
 * @param imageType The type of image which is to be processed.
 * @param border How the border should be handled.  If null {@link BorderType#EXTENDED} will be used.
 * @return Filter for performing a sparse laplacian.
 */
public static <T extends ImageGray<T>> ImageFunctionSparse<T> createLaplacian(Class<T> imageType, ImageBorder<T> border) {
    if (border == null) {
        border = FactoryImageBorder.single(imageType, BorderType.EXTENDED);
    }
    if (GeneralizedImageOps.isFloatingPoint(imageType)) {
        ImageConvolveSparse<GrayF32, Kernel2D_F32> r = FactoryConvolveSparse.convolve2D(GrayF32.class, LaplacianEdge.kernel_F32);
        r.setImageBorder((ImageBorder_F32) border);
        return (ImageFunctionSparse<T>) r;
    } else {
        ImageConvolveSparse r = FactoryConvolveSparse.convolve2D(GrayI.class, LaplacianEdge.kernel_I32);
        r.setImageBorder(border);
        return (ImageFunctionSparse<T>) r;
    }
}
Also used : ImageFunctionSparse(boofcv.abst.filter.ImageFunctionSparse) GrayF32(boofcv.struct.image.GrayF32) Kernel2D_F32(boofcv.struct.convolve.Kernel2D_F32) ImageConvolveSparse(boofcv.abst.filter.convolve.ImageConvolveSparse)

Example 10 with Kernel2D_F32

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

the class DescribeSiftCommon method createGaussianWeightKernel.

/**
 * Creates a gaussian weighting kernel with an even number of elements along its width
 */
protected static float[] createGaussianWeightKernel(double sigma, int radius) {
    Kernel2D_F32 ker = FactoryKernelGaussian.gaussian2D_F32(sigma, radius, false, false);
    float maxValue = KernelMath.maxAbs(ker.data, 4 * radius * radius);
    KernelMath.divide(ker, maxValue);
    return ker.data;
}
Also used : Kernel2D_F32(boofcv.struct.convolve.Kernel2D_F32)

Aggregations

Kernel2D_F32 (boofcv.struct.convolve.Kernel2D_F32)25 Test (org.junit.Test)15 GrayF32 (boofcv.struct.image.GrayF32)13 ImageBorder_F32 (boofcv.core.image.border.ImageBorder_F32)7 ImageFunctionSparse (boofcv.abst.filter.ImageFunctionSparse)1 ImageConvolveSparse (boofcv.abst.filter.convolve.ImageConvolveSparse)1 BorderIndex1D_Extend (boofcv.core.image.border.BorderIndex1D_Extend)1 ImageBorder1D_F32 (boofcv.core.image.border.ImageBorder1D_F32)1 Kernel1D_F32 (boofcv.struct.convolve.Kernel1D_F32)1 Kernel2D (boofcv.struct.convolve.Kernel2D)1