Ask Your Question

Revision history [back]

Let me combine the remarks in an answer so that we can close this one down.


ANSWER TO THE ORIGINAL QUESTION

Without knowing exactly what the code of watershed does (i do know the principle, just haven't done it yet in openCV) I can say that the first part is basically creating different colors for filling each component. For doing this the random number generator functionality of OpenCV is used. For the amount of components a BGR color scalar is pushed back to the colorTab vector.

As to the second code snippet, this basically fills up the retrieved regions of the components and fills them with the retrieved color for that component. It is then placed as an overlay image on top of the grayscale image.


ANSWER TO EXTRA REMARKS

By creating a mask based on the indexes. Basically what you do is creating a 3D matrix construction. Each channel of your image will correspond to one of the indexes. Then loop over the image x and y positions and for each element check which index they have. Then set at that channel, inside the 3D matrix structure, the value on 1 instead of zeros. This will create all the masks to seperate the different regions.

and

No they will if you keep 1 indices strictly to the seperate masks. You could then check for overlapping boundaries, but afaik each pixel can only have a single index and not multiple, so there should be NO overlap of regions, not even a single pixel border.


Please if this fixed your problem, do accept this as the solution to the problem.