Search in sources :

Example 6 with ImageRectangle

use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.

the class ImplIntegralImageOps method convolveBorder.

public static void convolveBorder(GrayS64 integral, IntegralKernel kernel, GrayS64 output, int borderX, int borderY) {
    for (int x = 0; x < integral.width; x++) {
        for (int y = 0; y < borderY; y++) {
            long total = 0;
            for (int i = 0; i < kernel.blocks.length; i++) {
                ImageRectangle b = kernel.blocks[i];
                total += block_zero(integral, x + b.x0, y + b.y0, x + b.x1, y + b.y1) * kernel.scales[i];
            }
            output.set(x, y, total);
        }
        for (int y = integral.height - borderY; y < integral.height; y++) {
            long total = 0;
            for (int i = 0; i < kernel.blocks.length; i++) {
                ImageRectangle b = kernel.blocks[i];
                total += block_zero(integral, x + b.x0, y + b.y0, x + b.x1, y + b.y1) * kernel.scales[i];
            }
            output.set(x, y, total);
        }
    }
    int endY = integral.height - borderY;
    for (int y = borderY; y < endY; y++) {
        for (int x = 0; x < borderX; x++) {
            long total = 0;
            for (int i = 0; i < kernel.blocks.length; i++) {
                ImageRectangle b = kernel.blocks[i];
                total += block_zero(integral, x + b.x0, y + b.y0, x + b.x1, y + b.y1) * kernel.scales[i];
            }
            output.set(x, y, total);
        }
        for (int x = integral.width - borderX; x < integral.width; x++) {
            long total = 0;
            for (int i = 0; i < kernel.blocks.length; i++) {
                ImageRectangle b = kernel.blocks[i];
                total += block_zero(integral, x + b.x0, y + b.y0, x + b.x1, y + b.y1) * kernel.scales[i];
            }
            output.set(x, y, total);
        }
    }
}
Also used : ImageRectangle(boofcv.struct.ImageRectangle)

Example 7 with ImageRectangle

use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.

the class ImplIntegralImageOps method convolveBorder.

public static void convolveBorder(GrayF32 integral, IntegralKernel kernel, GrayF32 output, int borderX, int borderY) {
    for (int x = 0; x < integral.width; x++) {
        for (int y = 0; y < borderY; y++) {
            float total = 0;
            for (int i = 0; i < kernel.blocks.length; i++) {
                ImageRectangle b = kernel.blocks[i];
                total += block_zero(integral, x + b.x0, y + b.y0, x + b.x1, y + b.y1) * kernel.scales[i];
            }
            output.set(x, y, total);
        }
        for (int y = integral.height - borderY; y < integral.height; y++) {
            float total = 0;
            for (int i = 0; i < kernel.blocks.length; i++) {
                ImageRectangle b = kernel.blocks[i];
                total += block_zero(integral, x + b.x0, y + b.y0, x + b.x1, y + b.y1) * kernel.scales[i];
            }
            output.set(x, y, total);
        }
    }
    int endY = integral.height - borderY;
    for (int y = borderY; y < endY; y++) {
        for (int x = 0; x < borderX; x++) {
            float total = 0;
            for (int i = 0; i < kernel.blocks.length; i++) {
                ImageRectangle b = kernel.blocks[i];
                total += block_zero(integral, x + b.x0, y + b.y0, x + b.x1, y + b.y1) * kernel.scales[i];
            }
            output.set(x, y, total);
        }
        for (int x = integral.width - borderX; x < integral.width; x++) {
            float total = 0;
            for (int i = 0; i < kernel.blocks.length; i++) {
                ImageRectangle b = kernel.blocks[i];
                total += block_zero(integral, x + b.x0, y + b.y0, x + b.x1, y + b.y1) * kernel.scales[i];
            }
            output.set(x, y, total);
        }
    }
}
Also used : ImageRectangle(boofcv.struct.ImageRectangle)

Example 8 with ImageRectangle

use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.

the class TestIntegralImageOps method isInBounds.

@Test
public void isInBounds() {
    IntegralKernel kernel = new IntegralKernel(2);
    kernel.blocks[0] = new ImageRectangle(-1, -2, 1, 2);
    kernel.blocks[1] = new ImageRectangle(-3, -2, 1, 2);
    // obvious cases
    assertTrue(IntegralImageOps.isInBounds(30, 30, kernel, 100, 100));
    assertFalse(IntegralImageOps.isInBounds(-10, -20, kernel, 100, 100));
    // positive border cases
    assertTrue(IntegralImageOps.isInBounds(3, 30, kernel, 100, 100));
    assertTrue(IntegralImageOps.isInBounds(98, 30, kernel, 100, 100));
    assertTrue(IntegralImageOps.isInBounds(30, 2, kernel, 100, 100));
    assertTrue(IntegralImageOps.isInBounds(30, 97, kernel, 100, 100));
    // negative border cases
    assertFalse(IntegralImageOps.isInBounds(2, 30, kernel, 100, 100));
    assertFalse(IntegralImageOps.isInBounds(99, 30, kernel, 100, 100));
    assertFalse(IntegralImageOps.isInBounds(30, 1, kernel, 100, 100));
    assertFalse(IntegralImageOps.isInBounds(30, 98, kernel, 100, 100));
}
Also used : ImageRectangle(boofcv.struct.ImageRectangle) Test(org.junit.Test)

Example 9 with ImageRectangle

use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.

the class TestImplIntegralImageOps method convolveSparse.

public void convolveSparse(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramType = m.getParameterTypes();
    Class inputType = paramType[0];
    ImageGray integral = GeneralizedImageOps.createSingleBand(inputType, width, height);
    GImageMiscOps.fillUniform(integral, rand, 0, 1000);
    ImageGray expected = GeneralizedImageOps.createSingleBand(inputType, width, height);
    IntegralKernel kernel = new IntegralKernel(2);
    kernel.blocks[0] = new ImageRectangle(-2, -2, 1, 1);
    kernel.blocks[1] = new ImageRectangle(-2, -1, 1, 0);
    kernel.scales = new int[] { 1, 2 };
    GIntegralImageOps.convolve(integral, kernel, expected);
    GImageGray e = FactoryGImageGray.wrap(expected);
    double found0 = ((Number) m.invoke(null, integral, kernel, 0, 0)).doubleValue();
    double found1 = ((Number) m.invoke(null, integral, kernel, 10, 12)).doubleValue();
    double found2 = ((Number) m.invoke(null, integral, kernel, 19, 29)).doubleValue();
    assertEquals(e.get(0, 0).doubleValue(), found0, 1e-4f);
    assertEquals(e.get(10, 12).doubleValue(), found1, 1e-4f);
    assertEquals(e.get(19, 29).doubleValue(), found2, 1e-4f);
}
Also used : IntegralKernel(boofcv.alg.transform.ii.IntegralKernel) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageRectangle(boofcv.struct.ImageRectangle) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray)

Example 10 with ImageRectangle

use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.

the class TestImplIntegralImageOps method convolve.

public void convolve(Method m) throws InvocationTargetException, IllegalAccessException {
    Kernel2D_S32 kernel = new Kernel2D_S32(3, new int[] { 1, 1, 1, 2, 2, 2, 1, 1, 1 });
    GrayU8 input = new GrayU8(width, height);
    GrayS32 expected = new GrayS32(width, height);
    GImageMiscOps.fillUniform(input, rand, 0, 10);
    ImageBorder_S32 border = FactoryImageBorderAlgs.value(input, 0);
    ConvolveImage.convolve(kernel, input, expected, border);
    Class[] paramType = m.getParameterTypes();
    Class inputType = paramType[0];
    Class outputType = paramType[2];
    ImageGray inputII = GeneralizedImageOps.createSingleBand(inputType, width, height);
    ImageGray integral = GeneralizedImageOps.createSingleBand(outputType, width, height);
    ImageGray expectedII = GeneralizedImageOps.createSingleBand(outputType, width, height);
    ImageGray found = GeneralizedImageOps.createSingleBand(outputType, width, height);
    GConvertImage.convert(input, inputII);
    GConvertImage.convert(expected, expectedII);
    GIntegralImageOps.transform(inputII, integral);
    IntegralKernel kernelII = new IntegralKernel(2);
    kernelII.blocks[0] = new ImageRectangle(-2, -2, 1, 1);
    kernelII.blocks[1] = new ImageRectangle(-2, -1, 1, 0);
    kernelII.scales = new int[] { 1, 1 };
    m.invoke(null, integral, kernelII, found);
    BoofTesting.assertEqualsRelative(expected, found, 1e-4f);
}
Also used : Kernel2D_S32(boofcv.struct.convolve.Kernel2D_S32) IntegralKernel(boofcv.alg.transform.ii.IntegralKernel) ImageRectangle(boofcv.struct.ImageRectangle) GrayU8(boofcv.struct.image.GrayU8) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray) ImageBorder_S32(boofcv.core.image.border.ImageBorder_S32) GrayS32(boofcv.struct.image.GrayS32)

Aggregations

ImageRectangle (boofcv.struct.ImageRectangle)43 Test (org.junit.Test)15 GrayU8 (boofcv.struct.image.GrayU8)10 IntegralKernel (boofcv.alg.transform.ii.IntegralKernel)3 FactoryGImageGray (boofcv.core.image.FactoryGImageGray)3 GImageGray (boofcv.core.image.GImageGray)3 ImageGray (boofcv.struct.image.ImageGray)3 ImageBorder_S32 (boofcv.core.image.border.ImageBorder_S32)2 Kernel2D_S32 (boofcv.struct.convolve.Kernel2D_S32)2 GrayS32 (boofcv.struct.image.GrayS32)2 Point2D_F32 (georegression.struct.point.Point2D_F32)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 Point2D_I32 (georegression.struct.point.Point2D_I32)2 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)2 Rectangle2D_F64 (georegression.struct.shapes.Rectangle2D_F64)1 FastQueue (org.ddogleg.struct.FastQueue)1 GrowQueue_F64 (org.ddogleg.struct.GrowQueue_F64)1