Search in sources :

Example 11 with Kernel2D

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

the class TestBlurImageOps method mean.

// ImageType.il(2,InterleavedU8.class),ImageType.il(2,InterleavedF32.class)}; TODO add in future
@Test
public void mean() {
    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);
            int w = radius * 2 + 1;
            // convolve with a kernel to compute the expected value
            Kernel2D kernel = FactoryKernel.createKernelForImage(w, w / 2, 2, type.getDataType());
            FactoryKernel.setTable(kernel);
            GConvolveImageOps.convolveNormalized(kernel, input, expected);
            try {
                Class storage = type.getFamily() == ImageType.Family.PLANAR ? ImageGray.class : input.getClass();
                Method m = BlurImageOps.class.getMethod("mean", input.getClass(), found.getClass(), int.class, storage);
                m.invoke(null, input, found, 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)

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