Search in sources :

Example 6 with Edge

use of chapter4.section3.Edge in project BoofCV by lessthanoptimal.

the class FhEdgeWeights8_F32 method check.

private void check(int x, int y, float color0, int indexA, GrayF32 input, FastQueue<Edge> edges) {
    if (!input.isInBounds(x, y))
        return;
    int indexSrc = input.startIndex + y * input.stride + x;
    int indexB = +y * input.width + x;
    float colorN = input.data[indexSrc];
    Edge e1 = edges.grow();
    e1.sortValue = (float) Math.abs(color0 - colorN);
    e1.indexA = indexA;
    e1.indexB = indexB;
}
Also used : Edge(boofcv.alg.segmentation.fh04.SegmentFelzenszwalbHuttenlocher04.Edge)

Example 7 with Edge

use of chapter4.section3.Edge in project BoofCV by lessthanoptimal.

the class GenericFhEdgeWeightsChecks method basicTest.

@Test
public void basicTest() {
    T input = imageType.createImage(10, 12);
    GImageMiscOps.fillUniform(input, rand, 0, 200);
    FhEdgeWeights<T> alg = createAlg();
    FastQueue<Edge> edges = new FastQueue<>(Edge.class, true);
    alg.process(input, edges);
    int[] hist = new int[input.width * input.height];
    // see if the edges computed the expected weight
    for (int i = 0; i < edges.size(); i++) {
        Edge e = edges.get(i);
        int indexA = e.indexA;
        int indexB = e.indexB;
        hist[indexA]++;
        hist[indexB]++;
        float expected = weight(input, indexA, indexB);
        assertEquals(expected, e.weight(), 1e-4f);
    }
    // make sure each pixel was inspected
    if (rule == ConnectRule.FOUR) {
        for (int y = 0; y < input.height; y++) {
            for (int x = 0; x < input.width; x++) {
                if (x >= 1 && x < input.width - 1 && y >= 1 && y < input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 4);
                else if (x == 0 && y == 0)
                    assertEquals(hist[input.getIndex(x, y)], 2);
                else if (x == input.width - 1 && y == 0)
                    assertEquals(hist[input.getIndex(x, y)], 2);
                else if (x == input.width - 1 && y == input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 2);
                else if (x == 0 && y == input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 2);
                else {
                    assertEquals(hist[input.getIndex(x, y)], 3);
                }
            }
        }
    } else if (rule == ConnectRule.EIGHT) {
        for (int y = 0; y < input.height; y++) {
            for (int x = 0; x < input.width; x++) {
                if (x >= 1 && x < input.width - 1 && y >= 1 && y < input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 8);
                else if (x == 0 && y == 0)
                    assertEquals(hist[input.getIndex(x, y)], 3);
                else if (x == input.width - 1 && y == 0)
                    assertEquals(hist[input.getIndex(x, y)], 3);
                else if (x == input.width - 1 && y == input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 3);
                else if (x == 0 && y == input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 3);
                else {
                    assertEquals(hist[input.getIndex(x, y)], 5);
                }
            }
        }
    } else {
        throw new RuntimeException("Unknown rule");
    }
}
Also used : FastQueue(org.ddogleg.struct.FastQueue) Edge(boofcv.alg.segmentation.fh04.SegmentFelzenszwalbHuttenlocher04.Edge) Test(org.junit.Test)

Example 8 with Edge

use of chapter4.section3.Edge in project BoofCV by lessthanoptimal.

the class GenericFhEdgeWeightsChecks method subimage.

@Test
public void subimage() {
    T input = imageType.createImage(10, 12);
    GImageMiscOps.fillUniform(input, rand, 0, 200);
    T inputSub = BoofTesting.createSubImageOf(input);
    FhEdgeWeights<T> alg = createAlg();
    FastQueue<Edge> edges0 = new FastQueue<>(Edge.class, true);
    FastQueue<Edge> edges1 = new FastQueue<>(Edge.class, true);
    alg.process(input, edges0);
    alg.process(inputSub, edges1);
    // both should be identical
    assertEquals(edges0.size, edges1.size);
    for (int i = 0; i < edges0.size; i++) {
        Edge e0 = edges0.get(i);
        Edge e1 = edges1.get(i);
        assertEquals("i = " + i, e0.indexA, e1.indexA);
        assertEquals("i = " + i, e0.indexB, e1.indexB);
        assertEquals("i = " + i, e0.sortValue, e1.sortValue, 1e-4f);
    }
}
Also used : FastQueue(org.ddogleg.struct.FastQueue) Edge(boofcv.alg.segmentation.fh04.SegmentFelzenszwalbHuttenlocher04.Edge) Test(org.junit.Test)

Example 9 with Edge

use of chapter4.section3.Edge in project BoofCV by lessthanoptimal.

the class FhEdgeWeights4_F32 method check.

private void check(int x, int y, float color0, int indexA, GrayF32 input, FastQueue<Edge> edges) {
    if (!input.isInBounds(x, y))
        return;
    int indexSrc = input.startIndex + y * input.stride + x;
    int indexB = +y * input.width + x;
    float colorN = input.data[indexSrc];
    Edge e1 = edges.grow();
    e1.sortValue = (float) Math.abs(color0 - colorN);
    e1.indexA = indexA;
    e1.indexB = indexB;
}
Also used : Edge(boofcv.alg.segmentation.fh04.SegmentFelzenszwalbHuttenlocher04.Edge)

Example 10 with Edge

use of chapter4.section3.Edge in project BoofCV by lessthanoptimal.

the class FhEdgeWeights4_PLF32 method check.

private void check(int x, int y, float[] color0, int indexA, Planar<GrayF32> input, FastQueue<Edge> edges) {
    if (!input.isInBounds(x, y))
        return;
    int indexSrc = input.startIndex + y * input.stride + x;
    int indexB = +y * input.width + x;
    float weight = 0;
    for (int i = 0; i < numBands; i++) {
        GrayF32 band = input.getBand(i);
        float color = band.data[indexSrc];
        float diff = color0[i] - color;
        weight += diff * diff;
    }
    Edge e1 = edges.grow();
    e1.sortValue = (float) Math.sqrt(weight);
    e1.indexA = indexA;
    e1.indexB = indexB;
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Edge(boofcv.alg.segmentation.fh04.SegmentFelzenszwalbHuttenlocher04.Edge)

Aggregations

Edge (boofcv.alg.segmentation.fh04.SegmentFelzenszwalbHuttenlocher04.Edge)18 GrayF32 (boofcv.struct.image.GrayF32)4 GrayU8 (boofcv.struct.image.GrayU8)4 FastQueue (org.ddogleg.struct.FastQueue)2 Test (org.junit.Test)2 Queue (chapter1.section3.Queue)1 UnionFind (chapter1.section5.UnionFind)1 PriorityQueueResize (chapter2.section4.PriorityQueueResize)1 SeparateChainingHashTable (chapter3.section4.SeparateChainingHashTable)1 HashSet (chapter3.section5.HashSet)1 OptimizedGraph (chapter4.section1.OptimizedGraph)1 TwoColor (chapter4.section1.TwoColor)1 Edge (chapter4.section3.Edge)1 EdgeWeightedGraph (chapter4.section3.EdgeWeightedGraph)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1