Search in sources :

Example 1 with Kernel2D

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

the class TestBlurImageOps method gaussian.

@Test
public void gaussian() {
    for (ImageType type : imageTypes) {
        ImageBase input = type.createImage(width, height);
        ImageBase found = type.createImage(width, height);
        ImageBase expected = type.createImage(width, height);
        GImageMiscOps.fillUniform(input, rand, 0, 20);
        for (int radius = 1; radius <= 4; radius++) {
            GImageMiscOps.fill(expected, 0);
            GImageMiscOps.fill(found, 0);
            // convolve with a kernel to compute the expected value
            Kernel2D kernel = FactoryKernelGaussian.gaussian2D(type.getDataType(), -1, radius);
            GConvolveImageOps.convolveNormalized(kernel, input, expected);
            try {
                Class storage = type.getFamily() == ImageType.Family.PLANAR ? ImageGray.class : input.getClass();
                Method m = BlurImageOps.class.getMethod("gaussian", input.getClass(), found.getClass(), double.class, int.class, storage);
                m.invoke(null, input, found, -1, radius, null);
                BoofTesting.assertEquals(expected, found, 2);
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : Method(java.lang.reflect.Method) Kernel2D(boofcv.struct.convolve.Kernel2D) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Example 2 with Kernel2D

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

the class GImageDerivativeOps method createAnyDerivatives.

/**
 * <p>
 * Convenience function for creating an instance of {@link boofcv.abst.filter.derivative.AnyImageDerivative}.
 * This class is an any way to compute any derivative of any order using the specified kernel.  It might
 * use more memory or be more expensive the specialized code but is easy to use.
 * </p>
 *
 * @param type Type of gradient to use
 * @param inputType Type of input image.
 * @param derivType Type of derivative image
 * @param <I> Image type.
 * @param <D> Image derivative type.
 * @return AnyImageDerivative
 */
public static <I extends ImageGray<I>, D extends ImageGray<D>> AnyImageDerivative<I, D> createAnyDerivatives(DerivativeType type, Class<I> inputType, Class<D> derivType) {
    boolean isInteger = !GeneralizedImageOps.isFloatingPoint(inputType);
    KernelBase kernel = lookupKernelX(type, isInteger);
    if (kernel instanceof Kernel1D)
        return new AnyImageDerivative<>((Kernel1D) kernel, inputType, derivType);
    else
        return new AnyImageDerivative<>((Kernel2D) kernel, inputType, derivType);
}
Also used : Kernel1D(boofcv.struct.convolve.Kernel1D) KernelBase(boofcv.struct.convolve.KernelBase) Kernel2D(boofcv.struct.convolve.Kernel2D)

Example 3 with Kernel2D

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

the class TestConvolveImageStandard_IL method convolve.

/**
 * Unit test for 2D convolution.
 */
public void convolve(ImageInterleaved img, ImageInterleaved dest) {
    Kernel2D ker = FactoryKernel.createKernelForImage(kernelWidth, kernelRadius, 2, img.getDataType());
    // standard symmetric odd kernel shape
    ker = FactoryKernel.random(ker.getClass(), kernelWidth, kernelRadius, 0, maxKernelValue, rand);
    convolve(ker, img, dest);
    // odd non-symmetric kernel shape
    ker = FactoryKernel.random(ker.getClass(), kernelWidth, 0, 0, maxKernelValue, rand);
    convolve(ker, img, dest);
    // even non-symmetric kernel shape
    ker = FactoryKernel.random(ker.getClass(), 2, 1, 0, maxKernelValue, rand);
    convolve(ker, img, dest);
}
Also used : Kernel2D(boofcv.struct.convolve.Kernel2D)

Example 4 with Kernel2D

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

the class TestConvolveImageStandard_IL method convolveDiv.

/**
 * Unit test for 2D convolution with division.
 */
public void convolveDiv(ImageInterleaved img, ImageInterleaved dest) {
    Kernel2D ker = FactoryKernel.createKernelForImage(kernelWidth, kernelRadius, 2, img.getDataType());
    // standard symmetric odd kernel shape
    ker = FactoryKernel.random(ker.getClass(), kernelWidth, kernelRadius, 0, maxKernelValue, rand);
    convolveDiv(ker, img, dest);
    // odd non-symmetric kernel shape
    ker = FactoryKernel.random(ker.getClass(), kernelWidth, 0, 0, maxKernelValue, rand);
    convolveDiv(ker, img, dest);
    // even non-symmetric kernel shape
    ker = FactoryKernel.random(ker.getClass(), 2, 1, 0, maxKernelValue, rand);
    convolveDiv(ker, img, dest);
}
Also used : Kernel2D(boofcv.struct.convolve.Kernel2D)

Example 5 with Kernel2D

use of boofcv.struct.convolve.Kernel2D 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)

Aggregations

Kernel2D (boofcv.struct.convolve.Kernel2D)11 Test (org.junit.Test)4 Kernel1D (boofcv.struct.convolve.Kernel1D)3 FDistort (boofcv.abst.distort.FDistort)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 SteerableKernel (boofcv.alg.filter.kernel.SteerableKernel)1 SteerableKernel_F32 (boofcv.alg.filter.kernel.impl.SteerableKernel_F32)1 SteerableKernel_I32 (boofcv.alg.filter.kernel.impl.SteerableKernel_I32)1 Kernel2D_F32 (boofcv.struct.convolve.Kernel2D_F32)1 Kernel2D_S32 (boofcv.struct.convolve.Kernel2D_S32)1 KernelBase (boofcv.struct.convolve.KernelBase)1 ImageGray (boofcv.struct.image.ImageGray)1 BufferedImage (java.awt.image.BufferedImage)1