Search in sources :

Example 16 with ImageBorder_F32

use of boofcv.core.image.border.ImageBorder_F32 in project BoofCV by lessthanoptimal.

the class ImplEdgeNonMaxSuppressionCrude method border4.

/**
 * Just processes the image border.
 */
public static void border4(GrayF32 _intensity, GrayI derivX, GrayI derivY, GrayF32 output) {
    int w = _intensity.width;
    int h = _intensity.height - 1;
    ImageBorder_F32 intensity = (ImageBorder_F32) FactoryImageBorderAlgs.value(_intensity, 0);
    // top border
    for (int x = 0; x < w; x++) {
        int dx, dy;
        if (derivX.get(x, 0) > 0)
            dx = 1;
        else
            dx = -1;
        if (derivY.get(x, 0) > 0)
            dy = 1;
        else
            dy = -1;
        float left = intensity.get(x - dx, -dy);
        float middle = intensity.get(x, 0);
        float right = intensity.get(x + dx, dy);
        if (left > middle || right > middle) {
            output.set(x, 0, 0);
        } else {
            output.set(x, 0, middle);
        }
    }
    // bottom border
    for (int x = 0; x < w; x++) {
        int dx, dy;
        if (derivX.get(x, h) > 0)
            dx = 1;
        else
            dx = -1;
        if (derivY.get(x, h) > 0)
            dy = 1;
        else
            dy = -1;
        float left = intensity.get(x - dx, h - dy);
        float middle = intensity.get(x, h);
        float right = intensity.get(x + dx, h + dy);
        if (left > middle || right > middle) {
            output.set(x, h, 0);
        } else {
            output.set(x, h, middle);
        }
    }
    // left border
    for (int y = 1; y < h; y++) {
        int dx, dy;
        if (derivX.get(0, y) > 0)
            dx = 1;
        else
            dx = -1;
        if (derivY.get(0, y) > 0)
            dy = 1;
        else
            dy = -1;
        float left = intensity.get(-dx, y - dy);
        float middle = intensity.get(0, y);
        float right = intensity.get(dx, y + dy);
        if (left > middle || right > middle) {
            output.set(0, y, 0);
        } else {
            output.set(0, y, middle);
        }
    }
    // right border
    w = w - 1;
    for (int y = 1; y < h; y++) {
        int dx, dy;
        if (derivX.get(w, y) > 0)
            dx = 1;
        else
            dx = -1;
        if (derivY.get(w, y) > 0)
            dy = 1;
        else
            dy = -1;
        float left = intensity.get(w - dx, y - dy);
        float middle = intensity.get(w, y);
        float right = intensity.get(w + dx, y + dy);
        if (left > middle || right > middle) {
            output.set(w, y, 0);
        } else {
            output.set(w, y, middle);
        }
    }
}
Also used : ImageBorder_F32(boofcv.core.image.border.ImageBorder_F32)

Example 17 with ImageBorder_F32

use of boofcv.core.image.border.ImageBorder_F32 in project BoofCV by lessthanoptimal.

the class ImplEdgeNonMaxSuppressionCrude method border4.

/**
 * Just processes the image border.
 */
public static void border4(GrayF32 _intensity, GrayF32 derivX, GrayF32 derivY, GrayF32 output) {
    int w = _intensity.width;
    int h = _intensity.height - 1;
    ImageBorder_F32 intensity = (ImageBorder_F32) FactoryImageBorderAlgs.value(_intensity, 0);
    // top border
    for (int x = 0; x < w; x++) {
        int dx, dy;
        if (derivX.get(x, 0) > 0)
            dx = 1;
        else
            dx = -1;
        if (derivY.get(x, 0) > 0)
            dy = 1;
        else
            dy = -1;
        float left = intensity.get(x - dx, -dy);
        float middle = intensity.get(x, 0);
        float right = intensity.get(x + dx, dy);
        if (left > middle || right > middle) {
            output.set(x, 0, 0);
        } else {
            output.set(x, 0, middle);
        }
    }
    // bottom border
    for (int x = 0; x < w; x++) {
        int dx, dy;
        if (derivX.get(x, h) > 0)
            dx = 1;
        else
            dx = -1;
        if (derivY.get(x, h) > 0)
            dy = 1;
        else
            dy = -1;
        float left = intensity.get(x - dx, h - dy);
        float middle = intensity.get(x, h);
        float right = intensity.get(x + dx, h + dy);
        if (left > middle || right > middle) {
            output.set(x, h, 0);
        } else {
            output.set(x, h, middle);
        }
    }
    // left border
    for (int y = 1; y < h; y++) {
        int dx, dy;
        if (derivX.get(0, y) > 0)
            dx = 1;
        else
            dx = -1;
        if (derivY.get(0, y) > 0)
            dy = 1;
        else
            dy = -1;
        float left = intensity.get(-dx, y - dy);
        float middle = intensity.get(0, y);
        float right = intensity.get(dx, y + dy);
        if (left > middle || right > middle) {
            output.set(0, y, 0);
        } else {
            output.set(0, y, middle);
        }
    }
    // right border
    w = w - 1;
    for (int y = 1; y < h; y++) {
        int dx, dy;
        if (derivX.get(w, y) > 0)
            dx = 1;
        else
            dx = -1;
        if (derivY.get(w, y) > 0)
            dy = 1;
        else
            dy = -1;
        float left = intensity.get(w - dx, y - dy);
        float middle = intensity.get(w, y);
        float right = intensity.get(w + dx, y + dy);
        if (left > middle || right > middle) {
            output.set(w, y, 0);
        } else {
            output.set(w, y, middle);
        }
    }
}
Also used : ImageBorder_F32(boofcv.core.image.border.ImageBorder_F32)

Example 18 with ImageBorder_F32

use of boofcv.core.image.border.ImageBorder_F32 in project BoofCV by lessthanoptimal.

the class TestDerivativeIntegralImage method kernelHaarY.

@Test
public void kernelHaarY() {
    GrayF32 orig = new GrayF32(width, height);
    GrayF32 integral = new GrayF32(width, height);
    ImageMiscOps.fillUniform(orig, rand, 0, 20);
    GrayF32 expected = new GrayF32(width, height);
    GrayF32 found = new GrayF32(width, height);
    IntegralImageOps.transform(orig, integral);
    ImageBorder_F32 border = (ImageBorder_F32) FactoryImageBorderAlgs.value(orig, 0);
    for (int i = 1; i < 5; i++) {
        int size = i * 2;
        IntegralKernel kernelI = DerivativeIntegralImage.kernelHaarY(size, null);
        Kernel2D_F32 kernel = createHaarX(size);
        kernel = KernelMath.transpose(kernel);
        ConvolveImage.convolve(kernel, orig, expected, border);
        IntegralImageOps.convolve(integral, kernelI, found);
        BoofTesting.assertEquals(expected, found, 1e-2);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Kernel2D_F32(boofcv.struct.convolve.Kernel2D_F32) ImageBorder_F32(boofcv.core.image.border.ImageBorder_F32) Test(org.junit.Test)

Example 19 with ImageBorder_F32

use of boofcv.core.image.border.ImageBorder_F32 in project BoofCV by lessthanoptimal.

the class TestDerivativeIntegralImage method kernelDerivY.

@Test
public void kernelDerivY() {
    GrayF32 orig = new GrayF32(width, height);
    GrayF32 integral = new GrayF32(width, height);
    ImageMiscOps.fillUniform(orig, rand, 0, 20);
    GrayF32 expected = new GrayF32(width, height);
    GrayF32 found = new GrayF32(width, height);
    IntegralImageOps.transform(orig, integral);
    ImageBorder_F32 border = (ImageBorder_F32) FactoryImageBorderAlgs.value(orig, 0);
    for (int r = 1; r < 5; r++) {
        IntegralKernel kernelI = DerivativeIntegralImage.kernelDerivY(r, null);
        Kernel2D_F32 kernel = createDerivX(r);
        kernel = KernelMath.transpose(kernel);
        ConvolveImage.convolve(kernel, orig, expected, border);
        IntegralImageOps.convolve(integral, kernelI, found);
        BoofTesting.assertEquals(expected, found, 1e-2);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Kernel2D_F32(boofcv.struct.convolve.Kernel2D_F32) ImageBorder_F32(boofcv.core.image.border.ImageBorder_F32) Test(org.junit.Test)

Example 20 with ImageBorder_F32

use of boofcv.core.image.border.ImageBorder_F32 in project BoofCV by lessthanoptimal.

the class TestDerivativeIntegralImage method kernelDerivXY.

@Test
public void kernelDerivXY() {
    GrayF32 orig = new GrayF32(width, height);
    GrayF32 integral = new GrayF32(width, height);
    ImageMiscOps.fillUniform(orig, rand, 0, 20);
    GrayF32 expected = new GrayF32(width, height);
    GrayF32 found = new GrayF32(width, height);
    IntegralImageOps.transform(orig, integral);
    ImageBorder_F32 border = (ImageBorder_F32) FactoryImageBorderAlgs.value(orig, 0);
    for (int i = 1; i <= 5; i += 2) {
        int size = i * 3;
        IntegralKernel kernelI = DerivativeIntegralImage.kernelDerivXY(size, null);
        Kernel2D_F32 kernel = createDerivXY(size);
        ConvolveImage.convolve(kernel, orig, expected, border);
        IntegralImageOps.convolve(integral, kernelI, found);
        BoofTesting.assertEquals(expected, found, 1e-2);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Kernel2D_F32(boofcv.struct.convolve.Kernel2D_F32) ImageBorder_F32(boofcv.core.image.border.ImageBorder_F32) Test(org.junit.Test)

Aggregations

ImageBorder_F32 (boofcv.core.image.border.ImageBorder_F32)29 GrayF32 (boofcv.struct.image.GrayF32)20 Test (org.junit.Test)16 Kernel2D_F32 (boofcv.struct.convolve.Kernel2D_F32)7 ImageBorder_S32 (boofcv.core.image.border.ImageBorder_S32)2 ScalePoint (boofcv.struct.feature.ScalePoint)2 GrayS16 (boofcv.struct.image.GrayS16)2 ImageGray (boofcv.struct.image.ImageGray)2 Point2D_I16 (georegression.struct.point.Point2D_I16)2 QueueCorner (boofcv.struct.QueueCorner)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Random (java.util.Random)1