Search in sources :

Example 6 with ImageBorder

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

the class TestImplImageMiscOps method testCopy_Border_Gray.

private void testCopy_Border_Gray(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramTypes = m.getParameterTypes();
    ImageGray src = GeneralizedImageOps.createSingleBand(paramTypes[6], width, height);
    ImageBorder border = FactoryImageBorder.generic(BorderType.WRAP, src.getImageType());
    ImageGray dst = GeneralizedImageOps.createSingleBand(paramTypes[8], width + 3, height + 2);
    GImageMiscOps.fillUniform(src, rand, 0, 20);
    GImageMiscOps.fillUniform(dst, rand, 0, 20);
    // normal copy all inside
    srcCopy_Border_Gray(m, src, border, dst, 5, 8, 1, 2, 3, 4);
    // copy reader is larger and contains all of src
    srcCopy_Border_Gray(m, src, border, dst, width + 2, height + 2, -1, -1, 0, 0);
    // corner copy
    srcCopy_Border_Gray(m, src, border, dst, 5, 6, -3, -2, 1, 2);
}
Also used : ImageGray(boofcv.struct.image.ImageGray) ImageBorder(boofcv.struct.border.ImageBorder) FactoryImageBorder(boofcv.core.image.border.FactoryImageBorder)

Example 7 with ImageBorder

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

the class TestImplImageMiscOps method testGrowBorder.

private void testGrowBorder(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramTypes = m.getParameterTypes();
    ImageGray src = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
    ImageGray dst = GeneralizedImageOps.createSingleBand(paramTypes[6], 1, 1);
    ImageBorder extend = FactoryImageBorder.generic(BorderType.EXTENDED, src.getImageType());
    int borderX0 = 2;
    int borderX1 = 3;
    int borderY0 = 3;
    int borderY1 = 2;
    GImageMiscOps.fillUniform(src, rand, 0, 100);
    m.invoke(null, src, extend, borderX0, borderX1, borderY0, borderY1, dst);
    assertEquals(width + borderX0 + borderX1, dst.width);
    assertEquals(height + borderY0 + borderY1, dst.height);
    for (int y = 0; y < dst.height; y++) {
        int yy = Math.min(src.height - 1, Math.max(0, y - borderY0));
        for (int x = 0; x < dst.width; x++) {
            int xx = Math.min(src.width - 1, Math.max(0, x - borderX0));
            // manually do the extend border
            double expected = GeneralizedImageOps.get(src, xx, yy);
            double found = GeneralizedImageOps.get(dst, x, y);
            assertEquals(expected, found, UtilEjml.TEST_F64, x + " " + y);
        }
    }
}
Also used : ImageGray(boofcv.struct.image.ImageGray) ImageBorder(boofcv.struct.border.ImageBorder) FactoryImageBorder(boofcv.core.image.border.FactoryImageBorder)

Example 8 with ImageBorder

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

the class TestImplCensusTransformBorder method region3x3.

@Test
void region3x3() {
    Random rand = new Random(234);
    for (ImageType type : new ImageType[] { ImageType.SB_U8, ImageType.SB_F32 }) {
        ImageGray input = (ImageGray) type.createImage(w, h);
        var found = new GrayU8(w, h);
        var expected = new GrayU8(w, h);
        ImageBorder border = FactoryImageBorder.wrap(BorderType.EXTENDED, input);
        if (type.getDataType().isInteger()) {
            GImageMiscOps.fillUniform(input, rand, 0, 255);
            ImplCensusTransformBorder.dense3x3_U8((ImageBorder_S32) border, found);
        } else {
            GImageMiscOps.fillUniform(input, rand, -2, 2);
            ImplCensusTransformBorder.dense3x3_F32((ImageBorder_F32) border, found);
        }
        CensusNaive.region3x3(input, expected);
        BoofTesting.assertEqualsBorder(expected, found, 0, 1, 1);
    }
}
Also used : Random(java.util.Random) ImageBorder(boofcv.struct.border.ImageBorder) FactoryImageBorder(boofcv.core.image.border.FactoryImageBorder) Test(org.junit.jupiter.api.Test)

Example 9 with ImageBorder

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

the class TestImplCensusTransformBorder method sample_U64.

@Test
void sample_U64() {
    Random rand = new Random(234);
    int r = 3;
    for (ImageType type : new ImageType[] { ImageType.SB_U8, ImageType.SB_F32 }) {
        ImageGray input = (ImageGray) type.createImage(w, h);
        var found = new GrayS64(w, h);
        var expected = new GrayS64(w, h);
        ImageBorder border = FactoryImageBorder.wrap(BorderType.EXTENDED, input);
        DogArray<Point2D_I32> samples = createSamples(r);
        if (type.getDataType().isInteger()) {
            GImageMiscOps.fillUniform(input, rand, 0, 255);
            ImplCensusTransformBorder.sample_S64((ImageBorder_S32) border, r, samples, found);
        } else {
            GImageMiscOps.fillUniform(input, rand, -2, 2);
            ImplCensusTransformBorder.sample_S64((ImageBorder_F32) border, r, samples, found);
        }
        CensusNaive.sample(input, samples, expected);
        BoofTesting.assertEqualsBorder(expected, found, 0, r, r);
    }
}
Also used : Random(java.util.Random) Point2D_I32(georegression.struct.point.Point2D_I32) ImageBorder(boofcv.struct.border.ImageBorder) FactoryImageBorder(boofcv.core.image.border.FactoryImageBorder) Test(org.junit.jupiter.api.Test)

Example 10 with ImageBorder

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

the class TestImplCensusTransformBorder method region5x5.

@Test
void region5x5() {
    Random rand = new Random(234);
    for (ImageType type : new ImageType[] { ImageType.SB_U8, ImageType.SB_F32 }) {
        ImageGray input = (ImageGray) type.createImage(w, h);
        var found = new GrayS32(w, h);
        var expected = new GrayS32(w, h);
        ImageBorder border = FactoryImageBorder.wrap(BorderType.EXTENDED, input);
        if (type.getDataType().isInteger()) {
            GImageMiscOps.fillUniform(input, rand, 0, 255);
            ImplCensusTransformBorder.dense5x5_U8((ImageBorder_S32) border, found);
        } else {
            GImageMiscOps.fillUniform(input, rand, -2, 2);
            ImplCensusTransformBorder.dense5x5_F32((ImageBorder_F32) border, found);
        }
        CensusNaive.region5x5(input, expected);
        BoofTesting.assertEqualsBorder(expected, found, 0, 2, 2);
    }
}
Also used : Random(java.util.Random) ImageBorder(boofcv.struct.border.ImageBorder) FactoryImageBorder(boofcv.core.image.border.FactoryImageBorder) Test(org.junit.jupiter.api.Test)

Aggregations

ImageBorder (boofcv.struct.border.ImageBorder)14 FactoryImageBorder (boofcv.core.image.border.FactoryImageBorder)12 Test (org.junit.jupiter.api.Test)7 ImageGray (boofcv.struct.image.ImageGray)5 Random (java.util.Random)4 KernelBase (boofcv.struct.convolve.KernelBase)2 Point2D_I32 (georegression.struct.point.Point2D_I32)2 ImageGradient (boofcv.abst.filter.derivative.ImageGradient)1 FactoryGImageGray (boofcv.core.image.FactoryGImageGray)1 GImageGray (boofcv.core.image.GImageGray)1 ImageBorderValue (boofcv.core.image.ImageBorderValue)1 ImageBorder_F32 (boofcv.struct.border.ImageBorder_F32)1 ImageBorder_S32 (boofcv.struct.border.ImageBorder_S32)1 Kernel2D (boofcv.struct.convolve.Kernel2D)1 GrayF32 (boofcv.struct.image.GrayF32)1 GrayI (boofcv.struct.image.GrayI)1 ImageBase (boofcv.struct.image.ImageBase)1 GradientValue (boofcv.struct.sparse.GradientValue)1 SparseImageGradient (boofcv.struct.sparse.SparseImageGradient)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1