library(EBImage)
The algorithm identifies and separates objects that stand out of the background (zero). After the water fill, the source image is flipped upside down and the resulting valleys (values with higher intensities) are filled in first until another object or background is met. The deepest valleys (pixels with highest intensity) become indexed first, starting from 1. [from ?watershed help]
x <- readImage(system.file('images', 'shapes.png', package='EBImage'))
x <- x[110:512,1:130]
display(x, title='Binary')
y <- distmap(x)
display(normalize(y), title='Distance map')
w <- watershed(y)
display(normalize(w), title='Watershed')
packageVersion("EBImage")
## [1] '4.8.2'
efg
2015-01-18 2031