Watershed
The no-knobs label node with a caveat
- image
- image
- label_image
- lut
Watershed is the odd one out in the Mosaica pack. Its two siblings, KMeans and MeanShift, both hand you a pile of knobs - cluster counts, bandwidths, color spaces, iteration limits. This node has exactly one input: the image. Plug it in, get back your image, label_image, and lut trio, done. For a beginner that zero-parameter life is a gift.
The caveat is that it's also the fussiest about the kind of image you feed it. Watershed is a classic OpenCV region-growing segmentation, and it thinks in intensity, not color. The pack README is upfront about it: watershed produces its best results on images with a lot of intensity variation, and it doesn't account for hue the way k-means and mean shift do.
How it works
The node runs the textbook OpenCV watershed pipeline, all in the shipped code: it grayscales the image, thresholds it with Otsu's method, opens it with a small morphological kernel to strip noise, dilates to find "sure background," runs a distance transform to find "sure foreground," marks everything with connected components, and finally lets cv.watershed flood the boundaries between those markers. Each flooded region becomes one label.
Because the segmentation is driven by brightness edges rather than color, you get the classic watershed failure modes. An image with flat, even lighting segments cleanly into nice regions. An image where a red object sits on a red background - similar intensity, different hue - will happily merge them into one blob. If your render looks like the node just gave up and made three giant regions, that's the intensity blindness, not a bug.
One nice detail: because the regions come from the actual image, the lut output holds the average color of each region as it appears in the original. So the colorized image output looks like a region-blurred version of your source - a genuinely different aesthetic from the pure cluster-average look of the other two Analyze nodes.
Wiring it up
There's only one input (the image), so the whole game is downstream. For a first test:
- Generate an image.
Watershed→label_image.Watershed→lut, or feedlabel_image+ aLoadLUTFromMatplotliborRandomLUTintoApplyLUTToLabelImagefor a custom palette.- Save and eyeball it.
Install and dependencies
Same pack, same story:
cd ComfyUI/custom_nodes
git clone https://github.com/Mason-McGough/ComfyUI-Mosaica
restart, done. Or use ComfyUI Manager and search "Mosaica". It depends on scikit-learn, opencv-python, and matplotlib, all CPU-side - no model files, no GPU work. The OpenCV dependency is the one that can bite on headless servers (libGL.so.1 errors → swap to opencv-python-headless).
When to reach for it
Watershed is the fastest of the three Analyze nodes - no parameter search, and the algorithm is quick. Use it when your source has strong brightness structure: product shots on clean backgrounds, high-contrast photography, generated images with dramatic lighting. Skip it for low-contrast or hue-driven subjects and use KMeans instead. It's the most "automatic" node in the pack, and it's also the one that needs you to pick your inputs wisely - just the image, but the image has to be the right kind.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| label_image | IMAGE | — |
| lut | IMAGE | — |