Search in sources :

Example 1 with BoofCheckFailure

use of boofcv.errors.BoofCheckFailure in project BoofCV by lessthanoptimal.

the class ConnectedTwoRowSpeckleFiller_U8 method fillCluster.

/**
 * Fill cluster by performing a search of connected pixels. This step can be slow and a memory hog
 * if the regions are large. It's also effectively the naive algorithm
 */
@Override
protected void fillCluster(int seedX, int seedY, int clusterSize) {
    int seedValue = image.unsafe_get(seedX, seedY);
    checkTrue(seedValue != fillValue, "BUG! Shouldn't have gotten this far");
    totalFilled++;
    image.unsafe_set(seedX, seedY, fillValue);
    open.reset();
    open.grow().setTo(seedX, seedY, seedValue);
    int foundSize = 0;
    while (!open.isEmpty()) {
        foundSize++;
        OpenPixel c = open.removeSwap(0);
        // create a copy because 'c' just got recycled and might be modified by the functions below!
        final int x = c.x;
        final int y = c.y;
        final int value = c.value;
        // check 4-connect neighborhood for pixels which are connected and add them to the open list
        // while marking them as visited
        checkAndConnect(x + 1, y, value, similarTol);
        checkAndConnect(x, y + 1, value, similarTol);
        checkAndConnect(x - 1, y, value, similarTol);
        checkAndConnect(x, y - 1, value, similarTol);
    }
    // Sanity check for bugs
    if (clusterSize != foundSize)
        throw new BoofCheckFailure("BUG! Fill does not match cluster size. Expected=" + clusterSize + " Found=" + foundSize);
}
Also used : BoofCheckFailure(boofcv.errors.BoofCheckFailure)

Example 2 with BoofCheckFailure

use of boofcv.errors.BoofCheckFailure in project BoofCV by lessthanoptimal.

the class ConnectedTwoRowSpeckleFiller_F32 method fillCluster.

/**
 * Fill cluster by performing a search of connected pixels. This step can be slow and a memory hog
 * if the regions are large. It's also effectively the naive algorithm
 */
@Override
protected void fillCluster(int seedX, int seedY, int clusterSize) {
    float seedValue = image.unsafe_get(seedX, seedY);
    checkTrue(seedValue != fillValue, "BUG! Shouldn't have gotten this far");
    totalFilled++;
    image.unsafe_set(seedX, seedY, fillValue);
    open.reset();
    open.grow().setTo(seedX, seedY, seedValue);
    int foundSize = 0;
    while (!open.isEmpty()) {
        foundSize++;
        OpenPixel c = open.removeSwap(0);
        // create a copy because 'c' just got recycled and might be modified by the functions below!
        final int x = c.x;
        final int y = c.y;
        final float value = c.value;
        // check 4-connect neighborhood for pixels which are connected and add them to the open list
        // while marking them as visited
        checkAndConnect(x + 1, y, value, similarTol);
        checkAndConnect(x, y + 1, value, similarTol);
        checkAndConnect(x - 1, y, value, similarTol);
        checkAndConnect(x, y - 1, value, similarTol);
    }
    // Sanity check for bugs
    if (clusterSize != foundSize)
        throw new BoofCheckFailure("BUG! Fill does not match cluster size. Expected=" + clusterSize + " Found=" + foundSize);
}
Also used : BoofCheckFailure(boofcv.errors.BoofCheckFailure)

Example 3 with BoofCheckFailure

use of boofcv.errors.BoofCheckFailure in project BoofCV by lessthanoptimal.

the class LearnNodeWeights method fixate.

/**
 * Call when done. This will compute the weight using an entropy like function: weight[i] = log(N/N[i]) where
 * N[i] is the number of times a specific node/work appears at least once in the images.
 */
public void fixate() {
    // root is always zero since all images are in it
    tree.nodes.get(0).weight = 0;
    // Compute the threshold relative to the total number of images
    int maxImagesInNode = maximumNumberImagesInNode.computeI(totalImages);
    for (int i = 1; i < tree.nodes.size; i++) {
        Node n = tree.nodes.get(i);
        int totalImagesFoundInsideOf = numberOfImagesWithNode.get(n.index);
        // become part of the image descriptor
        if (totalImagesFoundInsideOf > maxImagesInNode) {
            n.weight = 0;
            continue;
        }
        if (totalImagesFoundInsideOf == 0) {
            // never observed.
            if (checkEveryNodeSeenOnce)
                throw new BoofCheckFailure("Every node should have been seen by at least 1 image if feed the " + "same images the tree was trained from.");
            n.weight = 0;
        } else {
            n.weight = Math.log(totalImages / (double) totalImagesFoundInsideOf);
        }
    }
}
Also used : BoofCheckFailure(boofcv.errors.BoofCheckFailure) Node(boofcv.alg.scene.vocabtree.HierarchicalVocabularyTree.Node)

Aggregations

BoofCheckFailure (boofcv.errors.BoofCheckFailure)3 Node (boofcv.alg.scene.vocabtree.HierarchicalVocabularyTree.Node)1