valleys in the gradient image that are connected with the segments.
Figure 6-24 clarifies this process.
The function specification of the watershed segmentation algorithm is:
void cv::watershed(
cv::InputArray image, // Input 8-bit, 3 channels
cv::InputOutputArray markers // I/O 32-bit float, single channel
);
Here, image must be an 8-bit, 3-channel (color) image and markers is a single-channel integer
(cv::S32) image of the same (𝑥, 𝑦) dimensions. On input, the value of markers is 0 except where the
user (or an algorithm) has indicated by using positive numbers that some regions belong together. For
example, in the left panel of
Figure 6-24, the orange might have been marked with a 1, the lemon with a 2, the lime with 3, the upper
background with 4, and so on.
After the algorithm has run, all of the former zero value pixels in markers will be set to one of the given
markers (i.e., all of the pixels of the orange are hoped to come out with a 1 on them, the pixels of the lemon
with a 2, etc.), except the boundary pixels between regions, which will be set to -1.
Figure 6-24 (right) shows an example of such a segmentation.