Search in sources :

Example 6 with ImageBorder1D_F32

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

the class TestKltTracker method testTracking_border1.

/**
 * Create a description of a feature next to the border then place the feature just outside of the image
 * and see if it can track to its original position.
 */
@Test
void testTracking_border1() {
    ImageMiscOps.fillUniform(image, rand, 0, 100);
    GradientSobel.process(image, derivX, derivY, new ImageBorder1D_F32(BorderIndex1D_Extend::new));
    KltTracker<GrayF32, GrayF32> tracker = createDefaultTracker();
    tracker.setImage(image, derivX, derivY);
    int r = 4;
    KltFeature feature = new KltFeature(r);
    // lower right border, but fully inside the image
    feature.setPosition(imageWidth - r - 1, imageHeight - r - 1);
    tracker.setDescription(feature);
    // put it partially outside the image
    feature.setPosition(imageWidth - r + 0.1f, imageHeight - r + 0.5f);
    // see if it got sucked back
    assertSame(KltTrackFault.SUCCESS, tracker.track(feature));
    assertEquals(imageWidth - r - 1, feature.x, 0.01);
    assertEquals(imageHeight - r - 1, feature.y, 0.01);
    // same thing but with the top left image
    feature.setPosition(r, r);
    tracker.setDescription(feature);
    // put it partially outside the image
    feature.setPosition(r - 0.5f, r - 1.1f);
    // see if it got sucked back
    assertSame(KltTrackFault.SUCCESS, tracker.track(feature));
    assertEquals(r, feature.x, 0.01);
    assertEquals(r, feature.y, 0.01);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) ImageBorder1D_F32(boofcv.struct.border.ImageBorder1D_F32) Test(org.junit.jupiter.api.Test)

Example 7 with ImageBorder1D_F32

use of boofcv.struct.border.ImageBorder1D_F32 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 8 with ImageBorder1D_F32

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

the class TestFactoryConvolve method convolve1D_F32.

@Test
void convolve1D_F32() {
    Kernel1D_F32 kernel = FactoryKernel.random1D_F32(kernelWidth, radius, 1, 6, rand);
    ConvolveInterface<GrayF32, GrayF32> conv;
    GrayF32 input = new GrayF32(width, height);
    GrayF32 found = new GrayF32(width, height);
    GrayF32 expected = new GrayF32(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, 1e-4f);
    // CHECK EXTENDED
    conv = FactoryConvolve.convolve(kernel, input.imageType, found.imageType, BorderType.EXTENDED, true);
    conv.process(input, found);
    ConvolveImage.horizontal(kernel, input, expected, new ImageBorder1D_F32(BorderIndex1D_Extend::new));
    BoofTesting.assertEquals(expected, found, 1e-4f);
    // CHECK NORMALIZED
    conv = FactoryConvolve.convolve(kernel, input.imageType, found.imageType, BorderType.NORMALIZED, true);
    conv.process(input, found);
    ConvolveImageNormalized.horizontal(kernel, input, expected);
    BoofTesting.assertEquals(expected, found, 1e-4f);
}
Also used : Kernel1D_F32(boofcv.struct.convolve.Kernel1D_F32) ImageBorder1D_F32(boofcv.struct.border.ImageBorder1D_F32) Test(org.junit.jupiter.api.Test)

Example 9 with ImageBorder1D_F32

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

the class TestFactoryConvolve method convolve2D_F32.

@Test
void convolve2D_F32() {
    Kernel2D_F32 kernel = FactoryKernel.random2D_F32(kernelWidth, radius, 1, 6, rand);
    ConvolveInterface<GrayF32, GrayF32> conv;
    GrayF32 input = new GrayF32(width, height);
    GrayF32 found = new GrayF32(width, height);
    GrayF32 expected = new GrayF32(width, height);
    ImageMiscOps.fillUniform(input, rand, 0, 5);
    // CHECK NO BORDER
    conv = FactoryConvolve.convolve(kernel, GrayF32.class, GrayF32.class, BorderType.SKIP);
    conv.process(input, found);
    ConvolveImageNoBorder.convolve(kernel, input, expected);
    BoofTesting.assertEquals(expected, found, 1e-4f);
    // CHECK EXTENDED
    conv = FactoryConvolve.convolve(kernel, GrayF32.class, GrayF32.class, BorderType.EXTENDED);
    conv.process(input, found);
    ConvolveImage.convolve(kernel, input, expected, new ImageBorder1D_F32(BorderIndex1D_Extend::new));
    BoofTesting.assertEquals(expected, found, 1e-4f);
    // CHECK NORMALIZED
    conv = FactoryConvolve.convolve(kernel, GrayF32.class, GrayF32.class, BorderType.NORMALIZED);
    conv.process(input, found);
    ConvolveImageNormalized.convolve(kernel, input, expected);
    BoofTesting.assertEquals(expected, found, 1e-4f);
}
Also used : Kernel2D_F32(boofcv.struct.convolve.Kernel2D_F32) ImageBorder1D_F32(boofcv.struct.border.ImageBorder1D_F32) Test(org.junit.jupiter.api.Test)

Aggregations

ImageBorder1D_F32 (boofcv.struct.border.ImageBorder1D_F32)9 Test (org.junit.jupiter.api.Test)7 GrayF32 (boofcv.struct.image.GrayF32)5 ImageBorder1D_S32 (boofcv.struct.border.ImageBorder1D_S32)1 Kernel1D_F32 (boofcv.struct.convolve.Kernel1D_F32)1 Kernel2D_F32 (boofcv.struct.convolve.Kernel2D_F32)1 ImageGray (boofcv.struct.image.ImageGray)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1