Search in sources :

Example 11 with Edge

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

the class FhEdgeWeights4_PLU8 method process.

@Override
public void process(Planar<GrayU8> input, FastQueue<Edge> edges) {
    edges.reset();
    int w = input.width - 1;
    int h = input.height - 1;
    // First consider the inner pixels
    for (int y = 0; y < h; y++) {
        int indexSrc = input.startIndex + y * input.stride + 0;
        int indexDst = +y * input.width + 0;
        for (int x = 0; x < w; x++, indexSrc++, indexDst++) {
            int weight1 = 0, weight2 = 0;
            for (int i = 0; i < numBands; i++) {
                GrayU8 band = input.getBand(i);
                // (x,y)
                int color0 = band.data[indexSrc] & 0xFF;
                // (x+1,y)
                int color1 = band.data[indexSrc + 1] & 0xFF;
                // (x,y+1)
                int color2 = band.data[indexSrc + input.stride] & 0xFF;
                int diff1 = color0 - color1;
                int diff2 = color0 - color2;
                weight1 += diff1 * diff1;
                weight2 += diff2 * diff2;
            }
            Edge e1 = edges.grow();
            Edge e2 = edges.grow();
            e1.sortValue = (float) Math.sqrt(weight1);
            e1.indexA = indexDst;
            e1.indexB = indexDst + 1;
            e2.sortValue = (float) Math.sqrt(weight2);
            e2.indexA = indexDst;
            e2.indexB = indexDst + input.width;
        }
    }
    // Handle border pixels
    for (int y = 0; y < h; y++) {
        checkAround(w, y, input, edges);
    }
    for (int x = 0; x < w; x++) {
        checkAround(x, h, input, edges);
    }
}
Also used : GrayU8(boofcv.struct.image.GrayU8) Edge(boofcv.alg.segmentation.fh04.SegmentFelzenszwalbHuttenlocher04.Edge)

Example 12 with Edge

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

the class FhEdgeWeights8_F32 method process.

@Override
public void process(GrayF32 input, FastQueue<Edge> edges) {
    int w = input.width - 1;
    int h = input.height - 1;
    // First consider the inner pixels
    for (int y = 0; y < h; y++) {
        int indexSrc = input.startIndex + y * input.stride + 1;
        int indexDst = +y * input.width + 1;
        for (int x = 1; x < w; x++, indexSrc++, indexDst++) {
            // (x,y)
            float color0 = input.data[indexSrc];
            // (x+1,y)
            float color1 = input.data[indexSrc + 1];
            // (x,y+1)
            float color2 = input.data[indexSrc + input.stride];
            Edge e1 = edges.grow();
            Edge e2 = edges.grow();
            e1.sortValue = Math.abs(color1 - color0);
            e1.indexA = indexDst;
            e1.indexB = indexDst + 1;
            e2.sortValue = Math.abs(color2 - color0);
            e2.indexA = indexDst;
            e2.indexB = indexDst + input.width;
            // (x+1,y+1)
            float color3 = input.data[indexSrc + 1 + input.stride];
            // (x-1,y+1)
            float color4 = input.data[indexSrc - 1 + input.stride];
            Edge e3 = edges.grow();
            Edge e4 = edges.grow();
            e3.sortValue = Math.abs(color3 - color0);
            e3.indexA = indexDst;
            e3.indexB = indexDst + 1 + input.width;
            e4.sortValue = Math.abs(color4 - color0);
            e4.indexA = indexDst;
            e4.indexB = indexDst - 1 + input.width;
        }
    }
    // Handle border pixels
    for (int y = 0; y < h; y++) {
        checkAround(0, y, input, edges);
        checkAround(w, y, input, edges);
    }
    for (int x = 0; x < w; x++) {
        checkAround(x, h, input, edges);
    }
}
Also used : Edge(boofcv.alg.segmentation.fh04.SegmentFelzenszwalbHuttenlocher04.Edge)

Example 13 with Edge

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

the class FhEdgeWeights8_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)

Example 14 with Edge

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

the class FhEdgeWeights8_PLF32 method process.

@Override
public void process(Planar<GrayF32> input, FastQueue<Edge> edges) {
    edges.reset();
    int w = input.width - 1;
    int h = input.height - 1;
    // First consider the inner pixels
    for (int y = 0; y < h; y++) {
        int indexSrc = input.startIndex + y * input.stride + 1;
        int indexDst = +y * input.width + 1;
        for (int x = 1; x < w; x++, indexSrc++, indexDst++) {
            float weight1 = 0, weight2 = 0, weight3 = 0, weight4 = 0;
            for (int i = 0; i < numBands; i++) {
                GrayF32 band = input.getBand(i);
                // (x,y)
                float color0 = band.data[indexSrc];
                // (x+1,y)
                float color1 = band.data[indexSrc + 1];
                // (x,y+1)
                float color2 = band.data[indexSrc + input.stride];
                float diff1 = color0 - color1;
                float diff2 = color0 - color2;
                weight1 += diff1 * diff1;
                weight2 += diff2 * diff2;
                // (x+1,y+1)
                float color3 = band.data[indexSrc + 1 + input.stride];
                // (x-1,y+1)
                float color4 = band.data[indexSrc - 1 + input.stride];
                float diff3 = color0 - color3;
                float diff4 = color0 - color4;
                weight3 += diff3 * diff3;
                weight4 += diff4 * diff4;
            }
            Edge e1 = edges.grow();
            Edge e2 = edges.grow();
            e1.sortValue = (float) Math.sqrt(weight1);
            e1.indexA = indexDst;
            e1.indexB = indexDst + 1;
            e2.sortValue = (float) Math.sqrt(weight2);
            e2.indexA = indexDst;
            e2.indexB = indexDst + input.width;
            Edge e3 = edges.grow();
            Edge e4 = edges.grow();
            e3.sortValue = (float) Math.sqrt(weight3);
            e3.indexA = indexDst;
            e3.indexB = indexDst + 1 + input.width;
            e4.sortValue = (float) Math.sqrt(weight4);
            e4.indexA = indexDst;
            e4.indexB = indexDst - 1 + input.width;
        }
    }
    // Handle border pixels
    for (int y = 0; y < h; y++) {
        checkAround(0, y, input, edges);
        checkAround(w, y, input, edges);
    }
    for (int x = 0; x < w; x++) {
        checkAround(x, h, input, edges);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Edge(boofcv.alg.segmentation.fh04.SegmentFelzenszwalbHuttenlocher04.Edge)

Example 15 with Edge

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

the class FhEdgeWeights8_PLU8 method check.

private void check(int x, int y, int[] color0, int indexA, Planar<GrayU8> 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++) {
        GrayU8 band = input.getBand(i);
        int color = band.data[indexSrc] & 0xFF;
        int 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 : GrayU8(boofcv.struct.image.GrayU8) 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