Search in sources :

Example 31 with ImageBorder_F32

use of boofcv.struct.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 = FactoryImageBorderAlgs.value(_intensity, 0);
    // CONCURRENT_BELOW BoofConcurrency.loopFor(0,w,x->{
    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);
        }
    }
    // CONCURRENT_BELOW BoofConcurrency.loopFor(0,w,x->{
    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);
        }
    }
    // CONCURRENT_BELOW BoofConcurrency.loopFor(1,h,y->{
    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);
        }
    }
    // CONCURRENT_ABOVE });
    // right border
    int ww = w - 1;
    // CONCURRENT_BELOW BoofConcurrency.loopFor(1,h,y->{
    for (int y = 1; y < h; y++) {
        int dx, dy;
        if (derivX.get(ww, y) > 0)
            dx = 1;
        else
            dx = -1;
        if (derivY.get(ww, y) > 0)
            dy = 1;
        else
            dy = -1;
        float left = intensity.get(ww - dx, y - dy);
        float middle = intensity.get(ww, y);
        float right = intensity.get(ww + dx, y + dy);
        if (left > middle || right > middle) {
            output.set(ww, y, 0);
        } else {
            output.set(ww, y, middle);
        }
    }
// CONCURRENT_ABOVE });
}
Also used : ImageBorder_F32(boofcv.struct.border.ImageBorder_F32)

Example 32 with ImageBorder_F32

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

the class ImplEdgeNonMaxSuppression method naive4.

/**
 * Slow algorithm which processes the whole image.
 */
public static void naive4(GrayF32 _intensity, GrayS8 direction, GrayF32 output) {
    final int w = _intensity.width;
    final int h = _intensity.height;
    ImageBorder_F32 intensity = FactoryImageBorderAlgs.value(_intensity, 0);
    // CONCURRENT_BELOW BoofConcurrency.loopFor(0,h,y->{
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int dir = direction.get(x, y);
            int dx, dy;
            if (dir == 0) {
                dx = 1;
                dy = 0;
            } else if (dir == 1) {
                dx = 1;
                dy = 1;
            } else if (dir == 2) {
                dx = 0;
                dy = 1;
            } else {
                dx = 1;
                dy = -1;
            }
            float left = intensity.get(x - dx, y - dy);
            float middle = intensity.get(x, y);
            float right = intensity.get(x + dx, y + dy);
            // suppress the value if either of its neighboring values are more than or equal to it
            if (left > middle || right > middle) {
                output.set(x, y, 0);
            } else {
                output.set(x, y, middle);
            }
        }
    }
// CONCURRENT_ABOVE });
}
Also used : ImageBorder_F32(boofcv.struct.border.ImageBorder_F32)

Example 33 with ImageBorder_F32

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

the class ImplEdgeNonMaxSuppression method border4.

/**
 * Just processes the image border.
 */
public static void border4(GrayF32 _intensity, GrayS8 direction, GrayF32 output) {
    int w = _intensity.width;
    int h = _intensity.height - 1;
    ImageBorder_F32 intensity = FactoryImageBorderAlgs.value(_intensity, 0);
    // CONCURRENT_BELOW BoofConcurrency.loopFor(0,w,x->{
    for (int x = 0; x < w; x++) {
        int dir = direction.get(x, 0);
        int dx, dy;
        if (dir == 0) {
            dx = 1;
            dy = 0;
        } else if (dir == 1) {
            dx = 1;
            dy = 1;
        } else if (dir == 2) {
            dx = 0;
            dy = 1;
        } else {
            dx = 1;
            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);
        }
    }
    // CONCURRENT_BELOW BoofConcurrency.loopFor(0,w,x->{
    for (int x = 0; x < w; x++) {
        int dir = direction.get(x, h);
        int dx, dy;
        if (dir == 0) {
            dx = 1;
            dy = 0;
        } else if (dir == 1) {
            dx = 1;
            dy = 1;
        } else if (dir == 2) {
            dx = 0;
            dy = 1;
        } else {
            dx = 1;
            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);
        }
    }
    // CONCURRENT_BELOW BoofConcurrency.loopFor(1,h,y->{
    for (int y = 1; y < h; y++) {
        int dir = direction.get(0, y);
        int dx, dy;
        if (dir == 0) {
            dx = 1;
            dy = 0;
        } else if (dir == 1) {
            dx = 1;
            dy = 1;
        } else if (dir == 2) {
            dx = 0;
            dy = 1;
        } else {
            dx = 1;
            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);
        }
    }
    // CONCURRENT_ABOVE });
    // right border
    int _w = w - 1;
    // CONCURRENT_BELOW BoofConcurrency.loopFor(1,h,y->{
    for (int y = 1; y < h; y++) {
        int dir = direction.get(_w, y);
        int dx, dy;
        if (dir == 0) {
            dx = 1;
            dy = 0;
        } else if (dir == 1) {
            dx = 1;
            dy = 1;
        } else if (dir == 2) {
            dx = 0;
            dy = 1;
        } else {
            dx = 1;
            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);
        }
    }
// CONCURRENT_ABOVE });
}
Also used : ImageBorder_F32(boofcv.struct.border.ImageBorder_F32)

Example 34 with ImageBorder_F32

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

the class TestImplEdgeNonMaxSuppressionCrude method border.

public static <D extends ImageGray<D>> void border(Method m, GrayF32 input, D derivX, D derivY, GrayF32 output) {
    Random rand = new Random(123);
    GImageMiscOps.fillUniform(input, rand, 0, 30);
    GImageMiscOps.fillUniform(derivX, rand, -30, 30);
    GImageMiscOps.fillUniform(derivY, rand, -30, 30);
    try {
        m.invoke(null, input, derivX, derivY, output);
        ImageBorder_F32 intensity = (ImageBorder_F32) FactoryImageBorderAlgs.value(input, 0);
        for (int y = 0; y < input.height; y++) {
            if (y != 0 && y != input.height - 1)
                continue;
            for (int x = 0; x < input.width; x++) {
                if (x != 0 && x != input.width - 1)
                    continue;
                int dx = GeneralizedImageOps.get(derivX, x, y) > 0 ? 1 : -1;
                int dy = GeneralizedImageOps.get(derivY, x, y) > 0 ? 1 : -1;
                float left = intensity.get(x - dx, y - dy);
                float middle = intensity.get(x, y);
                float right = intensity.get(x + dx, y + dy);
                assertEquals((left < middle && right < middle), output.get(x, y) != 0);
            }
        }
        // uniform case should be NOT suppressed
        GImageMiscOps.fill(input, 2);
        m.invoke(null, input, derivX, derivY, output);
        for (int y = 0; y < input.height; y++) {
            if (y != 0 && y != input.height - 1)
                continue;
            for (int x = 0; x < input.width; x++) {
                if (x != 0 && x != input.width - 1)
                    continue;
                // the two adjacent pixels could be outside the image, depending on gradient direction
                if ((x == 0 && y == 0) || (x == input.width - 1 && y == 0))
                    continue;
                if ((x == input.width - 1 && y == input.height - 1) || (x == 0 && y == input.height - 1))
                    continue;
                assertTrue(output.get(x, y) == 2);
            }
        }
    } catch (IllegalAccessException | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}
Also used : Random(java.util.Random) ImageBorder_F32(boofcv.struct.border.ImageBorder_F32) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ImageBorder_F32 (boofcv.struct.border.ImageBorder_F32)34 GrayF32 (boofcv.struct.image.GrayF32)25 Test (org.junit.jupiter.api.Test)17 Kernel2D_F32 (boofcv.struct.convolve.Kernel2D_F32)7 ImageBorder_S32 (boofcv.struct.border.ImageBorder_S32)2 GrayS16 (boofcv.struct.image.GrayS16)2 ImageGray (boofcv.struct.image.ImageGray)2 ScalePoint (boofcv.struct.feature.ScalePoint)1 Point2D_I16 (georegression.struct.point.Point2D_I16)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Random (java.util.Random)1