I would like to implement component labeling algo for a color image.
The color distances of the four neighbors from the current pixel at (i,j) are computed and the algorithm proceeds as follows:
If none of the neighbors have a color distance smaller than a predefined threshold(T), assign a new label to pixel (i,j).
If only one of the neighbors has a color distance smaller than T, assign its label to pixel (i,j).
(a) If two or more neighbors have color distance smaller than T, pixel at (i,j) is assigned the label of the one that has the least color distance.
(b) The label of the pixel with least color distance is also assigned to the other neighbor pixels.
(c) All the previously labeled pixels in the image that have the same label as that of the other neighbor pixels are re-assigned with the label of the pixel having the least color distance.
I want to implement the code in C++ using opencv library. What is the best data structure I can use to implement the above algorithm? Should I use a std::map to store the neighbor distance values?
Also, if any one condition satisfies(1-3), I need to assign the label of that corresponding pixel to the current pixel(i,j). So I also need to know which neighbor's label it is (i.e. left, top, upper left diagonal, upper right diagonal). How do I get that?