Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is a pseudocode of the algorithm I think would work:

for each pixel P in image
    if(P!=0)  //skip the 0 pixels
        neighbor_vector = getneighbors(P) //the list of the neighbor pixels marked 
                                          //in orange, without the zeros
        for each element E in neighbor_vector
            if(connections[P] doesn't contain E)
                connections[P].push_back(E)

connections is an array of vectors with as many elements as the number of labels. Each vector in the connections will contain the list of the neithboring labels to the current label.

The only step where you scan the pixels several times is in the getneighbors function. But this is inevitable, even with morphological operations.

Here is a pseudocode of the algorithm I think would work:

for each pixel P in image
    if(P!=0)  //skip the 0 pixels
        neighbor_vector = getneighbors(P) //the list of the neighbor pixels marked 
                                          //in orange, without the zeros
        for each element E in neighbor_vector
            if(connections[P] doesn't contain E)
                connections[P].push_back(E)

connections is an array of vectors with as many elements as the number of labels. Each vector in the connections will contain the list of the neithboring labels to the current label.

The only step where you scan the pixels several times is in the getneighbors function. But this is inevitable, even with morphological operations.

operations.

I think this algorithm is quite fast, and can be easily parallelized. Just be sure to avoid direct pixel access with the at operator.

Here is a pseudocode of the algorithm I think would work:

for each pixel P in image
    if(P!=0)  //skip the 0 pixels
        neighbor_vector = getneighbors(P) //the list of the neighbor pixels marked 
                                          //in orange, without the zeros
zeros and pixels with value P
        for each element E in neighbor_vector
            if(connections[P] doesn't contain E)
                connections[P].push_back(E)

connections is an array of vectors with as many elements as the number of labels. Each vector in the connections will contain the list of the neithboring labels to the current label.

The only step where you scan the pixels several times is in the getneighbors function. But this is inevitable, even with morphological operations.

I think this algorithm is quite fast, and can be easily parallelized. Just be sure to avoid direct pixel access with the at operator.

Here is a pseudocode of the algorithm I think would work:

for each pixel P in image
    if(P!=0)  //skip the 0 pixels
        neighbor_vector = getneighbors(P) //the list of the neighbor pixels marked 
                                          //in orange, without (marked in orange)
                                          //without the zeros and pixels with value P
        for each element E in neighbor_vector
            if(connections[P] doesn't contain E)
                connections[P].push_back(E)

connections is an array of vectors with as many elements as the number of labels. Each vector in the connections will contain the list of the neithboring labels to the current label.

The only step where you scan the pixels several times is in the getneighbors function. But this is inevitable, even with morphological operations.

I think this algorithm is quite fast, and can be easily parallelized. Just be sure to avoid direct pixel access with the at operator.