Search in sources :

Example 1 with ImageBorder

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

the class ImageBorderWrapped method wrap.

/**
 * Creates an ImageBorder for the two specified images. The offsets are created by dividing the difference
 * inside by 2. Border must be bigger the image.
 */
public static <T extends ImageGray<T>> ImageBorder<T> wrap(T border, T image) {
    int offsetX = (border.width - image.width) / 2;
    int offsetY = (border.height - image.height) / 2;
    ImageBorder<T> ret;
    if (border instanceof GrayI) {
        ret = new S32(offsetX, offsetY, (GrayI) border);
    } else if (border instanceof GrayF32) {
        ret = (ImageBorder) new F32(offsetX, offsetY, (GrayF32) border);
    } else {
        throw new RuntimeException("Not supported yet");
    }
    ret.setImage(image);
    return ret;
}
Also used : ImageBorder_S32(boofcv.struct.border.ImageBorder_S32) GrayF32(boofcv.struct.image.GrayF32) GrayF32(boofcv.struct.image.GrayF32) ImageBorder_F32(boofcv.struct.border.ImageBorder_F32) GrayI(boofcv.struct.image.GrayI) ImageBorder(boofcv.struct.border.ImageBorder)

Example 2 with ImageBorder

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

the class TestBlurImageOps method meanBorder.

@Test
void meanBorder() {
    for (ImageType type : imageTypes) {
        if (type.getFamily() == ImageType.Family.INTERLEAVED)
            continue;
        ImageBase input = type.createImage(width, height);
        ImageBase found = type.createImage(width, height);
        ImageBase expected = type.createImage(width, height);
        GImageMiscOps.fillUniform(input, rand, 0, 20);
        ImageBorder border = FactoryImageBorder.generic(BorderType.REFLECT, input.getImageType());
        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, border);
            Class storage = type.getFamily() == ImageType.Family.PLANAR ? ImageGray.class : input.getClass();
            Class work = GeneralizedImageOps.createGrowArray(type).getClass();
            Class borderType = ImageBorder.class;
            if (type.getFamily() == ImageType.Family.GRAY) {
                switch(type.getDataType()) {
                    case U8:
                        borderType = ImageBorder_S32.class;
                        break;
                    case F32:
                        borderType = ImageBorder_F32.class;
                        break;
                    default:
                        break;
                }
            }
            try {
                // Compare with image border
                if (type.getFamily() == ImageType.Family.PLANAR) {
                    work = GrowArray.class;
                    Method m = BlurImageOps.class.getMethod("meanB", input.getClass(), found.getClass(), int.class, int.class, borderType, storage, work);
                    m.invoke(null, input, found, radius, radius, border, null, null);
                } else {
                    Method m = BlurImageOps.class.getMethod("meanB", input.getClass(), found.getClass(), int.class, int.class, borderType, storage, work);
                    m.invoke(null, input, found, radius, radius, border, null, null);
                }
                BoofTesting.assertEquals(expected, found, 2);
                // Test will null border
                // zero the image
                GImageMiscOps.fill(found, 0);
                if (type.getFamily() == ImageType.Family.PLANAR) {
                    work = GrowArray.class;
                    Method m = BlurImageOps.class.getMethod("meanB", input.getClass(), found.getClass(), int.class, int.class, borderType, storage, work);
                    m.invoke(null, input, found, radius, radius, border, null, null);
                } else {
                    Method m = BlurImageOps.class.getMethod("meanB", input.getClass(), found.getClass(), int.class, int.class, borderType, storage, work);
                    m.invoke(null, input, found, radius, radius, border, null, null);
                }
                // Inner should be the same
                BoofTesting.assertEqualsInner(expected, found, 2, radius, radius, false);
                // outer should be zeros
                // When a new image is created it is filled with zeros. That's why this test works
                BoofTesting.assertEqualsBorder(expected.createSameShape(), found, 2, radius, radius);
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : Method(java.lang.reflect.Method) Kernel2D(boofcv.struct.convolve.Kernel2D) ImageBorder(boofcv.struct.border.ImageBorder) FactoryImageBorder(boofcv.core.image.border.FactoryImageBorder) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.jupiter.api.Test)

Example 3 with ImageBorder

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

the class TestConvolveImageMean method createInputParam.

@Override
protected Object[][] createInputParam(Method candidate, Method validation) {
    Class[] c = candidate.getParameterTypes();
    ImageGray input = GeneralizedImageOps.createSingleBand(c[0], width, height);
    ImageGray output = GeneralizedImageOps.createSingleBand(c[1], width, height);
    GImageMiscOps.fillUniform(input, rand, 0, 100);
    ImageBorder border = FactoryImageBorder.generic(BorderType.REFLECT, input.getImageType());
    Object[][] ret = new Object[2][];
    if (c.length == 4) {
        ret[0] = new Object[] { input, output, offset1, length1 };
        ret[1] = new Object[] { input, output, offset2, length2 };
    } else if (c.length == 5) {
        ret[0] = new Object[] { input, output, offset1, length1, null };
        ret[1] = new Object[] { input, output, offset2, length2, null };
        if (ImageBorder.class.isAssignableFrom(c[4])) {
            ret[0][4] = border;
            ret[1][4] = border;
        }
    } else {
        ret[0] = new Object[] { input, output, offset1, length1, border, null };
        ret[1] = new Object[] { input, output, offset2, length2, border, null };
    }
    return ret;
}
Also used : ImageGray(boofcv.struct.image.ImageGray) FactoryImageBorder(boofcv.core.image.border.FactoryImageBorder) ImageBorder(boofcv.struct.border.ImageBorder)

Example 4 with ImageBorder

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

the class TestConvolveJustBorder_General_SB method createInputParam.

@Override
protected Object[][] createInputParam(Method candidate, Method validation) {
    Class<?>[] paramTypes = candidate.getParameterTypes();
    // Adjust border size for the different  convolution types
    int kernelLength = 5;
    KernelBase kernel = createKernel(paramTypes[0], kernelLength, kernelLength / 2);
    ImageBase src = ConvolutionTestHelper.createImage(validation.getParameterTypes()[1], width, height);
    GImageMiscOps.fillUniform(src, rand, 0, 5);
    ImageBase dst = ConvolutionTestHelper.createImage(validation.getParameterTypes()[2], width, height);
    ImageBorder border = FactoryImageBorder.generic(borderType, src.getImageType());
    border.setImage(src);
    Object[][] ret = new Object[2][paramTypes.length];
    // normal symmetric odd kernel
    ret[0][0] = kernel;
    ret[0][1] = border;
    ret[0][2] = dst;
    if (paramTypes.length == 4)
        ret[0][3] = BoofTesting.primitive(3, paramTypes[3]);
    // change the offset
    kernel = createKernel(paramTypes[0], kernelLength, kernelLength / 2 - 1);
    ret[1][0] = kernel;
    ret[1][1] = border;
    ret[1][2] = ConvolutionTestHelper.createImage(validation.getParameterTypes()[2], width, height);
    if (paramTypes.length == 4)
        ret[1][3] = BoofTesting.primitive(3, paramTypes[3]);
    return ret;
}
Also used : KernelBase(boofcv.struct.convolve.KernelBase) ImageBorder(boofcv.struct.border.ImageBorder) FactoryImageBorder(boofcv.core.image.border.FactoryImageBorder) ImageBase(boofcv.struct.image.ImageBase)

Example 5 with ImageBorder

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

the class GeneralGradientSparse method compareToFullImage_Border.

@Test
void compareToFullImage_Border() {
    ImageBorder border = FactoryImageBorder.single(BorderType.EXTENDED, imageType);
    ImageGradient gradient = createGradient();
    gradient.setBorderType(BorderType.EXTENDED);
    gradient.process(image, derivX, derivY);
    SparseImageGradient alg = createAlg(border);
    alg.setImage(image);
    for (int i = 0; i < image.height; i++) {
        for (int j = 0; j < image.width; j++) {
            assertTrue(image.isInBounds(j, i), j + " " + i);
            GradientValue g = alg.compute(j, i);
            double expectedX = GeneralizedImageOps.get(derivX, j, i);
            double expectedY = GeneralizedImageOps.get(derivY, j, i);
            assertEquals(expectedX, g.getX(), 1e-4f);
            assertEquals(expectedY, g.getY(), 1e-4f);
        }
    }
}
Also used : SparseImageGradient(boofcv.struct.sparse.SparseImageGradient) GradientValue(boofcv.struct.sparse.GradientValue) ImageBorder(boofcv.struct.border.ImageBorder) FactoryImageBorder(boofcv.core.image.border.FactoryImageBorder) ImageGradient(boofcv.abst.filter.derivative.ImageGradient) SparseImageGradient(boofcv.struct.sparse.SparseImageGradient) 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