1 | initial version |
If you meant: "all pixels with exact same values should go into the same cluster", use berak's answer. If you didn't I think we can improve on Guyygarty's answer.
Make a structure that holds a Point3i called color, and a vector of Point2i called pixels.
Make a mask the size of your image set to zero.
For every pixel that has the mask equal to zero, create a structure with the color it contains and push the location to the pixels vector, and set the mask to 255. Then recursively check every mask == 0 pixel it touches and if it's the same color add it to the vector and set the mask to 255.
For a refinement, make the mask image an int, and set the mask value to the index of the structure in the container you're storing them in.