Search in sources :

Example 1 with ImageBorder1D_S32

use of boofcv.struct.border.ImageBorder1D_S32 in project BoofCV by lessthanoptimal.

the class TestFactoryConvolve method convolve1D_I32.

@Test
void convolve1D_I32() {
    Kernel1D_S32 kernel = FactoryKernel.random1D_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, input.imageType, found.imageType, BorderType.SKIP, true);
    conv.process(input, found);
    ConvolveImageNoBorder.horizontal(kernel, input, expected);
    BoofTesting.assertEquals(expected, found, 0);
    // CHECK EXTENDED
    conv = FactoryConvolve.convolve(kernel, input.imageType, found.imageType, BorderType.EXTENDED, true);
    conv.process(input, found);
    ConvolveImage.horizontal(kernel, input, expected, new ImageBorder1D_S32(BorderIndex1D_Extend::new));
    BoofTesting.assertEquals(expected, found, 0);
    // CHECK NORMALIZED
    GrayU8 found8 = new GrayU8(width, height);
    GrayU8 expected8 = new GrayU8(width, height);
    conv = FactoryConvolve.convolve(kernel, input.imageType, ImageType.single(GrayI8.class), BorderType.NORMALIZED, true);
    conv.process(input, found8);
    ConvolveImageNormalized.horizontal(kernel, input, expected8);
    BoofTesting.assertEquals(expected8, found8, 0);
}
Also used : Kernel1D_S32(boofcv.struct.convolve.Kernel1D_S32) ImageBorder1D_S32(boofcv.struct.border.ImageBorder1D_S32) Test(org.junit.jupiter.api.Test)

Example 2 with ImageBorder1D_S32

use of boofcv.struct.border.ImageBorder1D_S32 in project BoofCV by lessthanoptimal.

the class StandardGradientChecks method testSecondDerivative.

/**
 * The XY and YX second derivatives should be indential
 */
private void testSecondDerivative(Method m1, Method m2) {
    Class[] params = m1.getParameterTypes();
    ImageGray input = GeneralizedImageOps.createSingleBand(params[0], width, height);
    ImageGray derivX = GeneralizedImageOps.createSingleBand(params[1], width, height);
    ImageGray derivY = GeneralizedImageOps.createSingleBand(params[2], width, height);
    ImageGray derivXX = GeneralizedImageOps.createSingleBand(params[1], width, height);
    ImageGray derivYY = GeneralizedImageOps.createSingleBand(params[2], width, height);
    ImageGray derivXY = GeneralizedImageOps.createSingleBand(params[1], width, height);
    ImageGray derivYX = GeneralizedImageOps.createSingleBand(params[1], width, height);
    GImageMiscOps.fillUniform(input, rand, 0, 40);
    Object border;
    if (params[3] == ImageBorder_F32.class) {
        border = new ImageBorder1D_F32(BorderIndex1D_Wrap::new);
    } else {
        border = new ImageBorder1D_S32(BorderIndex1D_Wrap::new);
    }
    try {
        m1.invoke(null, input, derivX, derivY, border);
        m2.invoke(null, derivX, derivXX, derivXY, border);
        m2.invoke(null, derivY, derivYX, derivYY, border);
    } catch (IllegalAccessException | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
    // BoofTesting.printDiff(derivXY,derivYX);
    BoofTesting.assertEquals(derivXY, derivYX, 1e-3f);
}
Also used : ImageBorder1D_F32(boofcv.struct.border.ImageBorder1D_F32) ImageGray(boofcv.struct.image.ImageGray) ImageBorder1D_S32(boofcv.struct.border.ImageBorder1D_S32) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with ImageBorder1D_S32

use of boofcv.struct.border.ImageBorder1D_S32 in project BoofCV by lessthanoptimal.

the class TestFactoryConvolve method convolve2D_I32.

@Test
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::new));
    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.struct.border.ImageBorder1D_S32) Test(org.junit.jupiter.api.Test)

Aggregations

ImageBorder1D_S32 (boofcv.struct.border.ImageBorder1D_S32)3 Test (org.junit.jupiter.api.Test)2 ImageBorder1D_F32 (boofcv.struct.border.ImageBorder1D_F32)1 Kernel1D_S32 (boofcv.struct.convolve.Kernel1D_S32)1 Kernel2D_S32 (boofcv.struct.convolve.Kernel2D_S32)1 ImageGray (boofcv.struct.image.ImageGray)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1