Search in sources :

Example 6 with Kernel2D_S32

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

the class ExampleConvolution method convolve2D.

/**
 * Convolves a 2D kernel
 */
private static void convolve2D(GrayU8 gray) {
    // By default 2D kernels will be centered around width/2
    Kernel2D_S32 kernel = new Kernel2D_S32(3);
    kernel.set(1, 0, 2);
    kernel.set(2, 1, 2);
    kernel.set(0, 1, -2);
    kernel.set(1, 2, -2);
    // Output needs to handle the increased domain after convolution.  Can't be 8bit
    GrayS16 output = new GrayS16(gray.width, gray.height);
    ImageBorder<GrayU8> border = FactoryImageBorder.wrap(BorderType.EXTENDED, gray);
    GConvolveImageOps.convolve(kernel, gray, output, border);
    panel.addImage(VisualizeImageData.standard(output, null), "2D Kernel");
}
Also used : Kernel2D_S32(boofcv.struct.convolve.Kernel2D_S32) GrayS16(boofcv.struct.image.GrayS16) GrayU8(boofcv.struct.image.GrayU8)

Example 7 with Kernel2D_S32

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

the class TestFactoryConvolve method convolve2D_I32.

@Test
public void convolve2D_I32() {
    Kernel2D_S32 kernel = FactoryKernel.random2D_I32(kernelWidth, radius, 1, 6, rand);
    ConvolveInterface conv;
    GrayU8 input = new GrayU8(width, height);
    GrayS16 found = new GrayS16(width, height);
    GrayS16 expected = new GrayS16(width, height);
    ImageMiscOps.fillUniform(input, rand, 0, 5);
    // CHECK NO BORDER
    conv = FactoryConvolve.convolve(kernel, GrayU8.class, GrayI16.class, BorderType.SKIP);
    conv.process(input, found);
    ConvolveImageNoBorder.convolve(kernel, input, expected);
    BoofTesting.assertEquals(expected, found, 0);
    // CHECK EXTENDED
    conv = FactoryConvolve.convolve(kernel, GrayU8.class, GrayI16.class, BorderType.EXTENDED);
    conv.process(input, found);
    ConvolveImage.convolve(kernel, input, expected, new ImageBorder1D_S32(BorderIndex1D_Extend.class));
    BoofTesting.assertEquals(expected, found, 0);
    // CHECK NORMALIZED
    GrayU8 found8 = new GrayU8(width, height);
    GrayU8 expected8 = new GrayU8(width, height);
    conv = FactoryConvolve.convolve(kernel, GrayU8.class, GrayU8.class, BorderType.NORMALIZED);
    conv.process(input, found8);
    ConvolveImageNormalized.convolve(kernel, input, expected8);
    BoofTesting.assertEquals(expected8, found8, 0);
}
Also used : Kernel2D_S32(boofcv.struct.convolve.Kernel2D_S32) ImageBorder1D_S32(boofcv.core.image.border.ImageBorder1D_S32) BorderIndex1D_Extend(boofcv.core.image.border.BorderIndex1D_Extend) Test(org.junit.Test)

Example 8 with Kernel2D_S32

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

the class TestFactoryConvolveDown method convolve2D_I32.

@Test
public void convolve2D_I32() {
    Kernel2D_S32 kernel = FactoryKernel.random2D_I32(kernelWidth, radius, 1, 6, rand);
    FilterImageInterface conv;
    GrayU8 input = new GrayU8(width, height);
    GrayS16 found = new GrayS16(width / skip, height / skip);
    GrayS16 expected = new GrayS16(width / skip, height / skip);
    ImageMiscOps.fillUniform(input, rand, 0, 5);
    // CHECK NO BORDER
    conv = FactoryConvolveDown.convolveSB(kernel, BorderType.SKIP, skip, GrayU8.class, GrayI16.class);
    conv.process(input, found);
    ConvolveImageDownNoBorder.convolve(kernel, input, expected, skip);
    BoofTesting.assertEquals(expected, found, 0);
    // CHECK EXTENDED
    // conv = FactoryConvolveDown.convolve( kernel,GrayU8.class,ImageInt16.class,BorderType.EXTENDED);
    // conv.process(input,found);
    // ConvolveWithBorder.convolve(kernel,input,expected);
    // BoofTesting.assertEquals(expected,found,0);
    // CHECK NORMALIZED
    GrayU8 found8 = new GrayU8(width / skip, height / skip);
    GrayU8 expected8 = new GrayU8(width / skip, height / skip);
    conv = FactoryConvolveDown.convolveSB(kernel, BorderType.NORMALIZED, skip, GrayU8.class, GrayU8.class);
    conv.process(input, found8);
    ConvolveImageDownNormalized.convolve(kernel, input, expected8, skip);
    BoofTesting.assertEquals(expected8, found8, 0);
}
Also used : FilterImageInterface(boofcv.abst.filter.FilterImageInterface) Kernel2D_S32(boofcv.struct.convolve.Kernel2D_S32) Test(org.junit.Test)

Example 9 with Kernel2D_S32

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

the class SteerableKernel_I32 method compute.

@Override
public Kernel2D_S32 compute(double angle) {
    // set the output to zero
    KernelMath.fill(output, 0);
    int N = output.width * output.width;
    for (int i = 0; i < basis.length; i++) {
        double c = coef.compute(angle, i);
        Kernel2D_S32 k = (Kernel2D_S32) basis[i];
        for (int j = 0; j < N; j++) {
            output.data[j] += k.data[j] * c;
        }
    }
    return output;
}
Also used : Kernel2D_S32(boofcv.struct.convolve.Kernel2D_S32)

Example 10 with Kernel2D_S32

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

the class SteerableKernel_I32 method setBasis.

@Override
public void setBasis(SteerableCoefficients coef, Kernel2D... basis) {
    this.coef = coef;
    this.basis = basis;
    int width = basis[0].width;
    output = new Kernel2D_S32(width);
}
Also used : Kernel2D_S32(boofcv.struct.convolve.Kernel2D_S32)

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