π Auto Zone Segmenter
Let k-means find your color zones so you don't have to
- image
- product_mask
- z0
- z1
- z2
- z3
- z4
- z5
- z6
- z7
- info
The "no manual masking" shortcut - with a caveat
Every other recolor node in this pack expects you to supply masks, and for a multi-zone garment that means clicking SAM a few times per article. This node is the shortcut: feed it the product photo plus one mask of the whole garment, tell it how many zones you want, and it clusters the pixels by color and hands back a separate mask per zone. Wire those straight into MultiZone Recolor and you've got the README's fully automatic colorway workflow.
But be clear about what it's doing. It's k-means clustering in LAB color space on the pixels inside your mask - it separates the garment into num_zones color clusters, not semantic regions. A black body with white stripes gives you exactly two obvious clusters, which is perfect. But a logo printed in the same color as the fabric will never be separated, and if you ask for more zones than the garment actually has, you get arbitrary splits of the same color rather than meaningful parts. It's automation, not understanding.
How it works
The node takes image and product_mask (the whole-garment mask - SAM or rembg, still your job), and num_zones (2β10, default 3). Inside, it converts to LAB, runs OpenCV's k-means with k-means++ seeding on the masked pixels, then cleans each cluster with morphological close/open so the masks aren't full of specks.
Outputs are eight z0 β¦ z7 MASK slots (unused ones come out as blank masks - wire the ones you care about) plus an info STRING that reports each zone's average RGB and its percentage of the masked area. That info string is genuinely useful: it tells you what "zone 0" actually is without eyeballing a mask, and it gives you the average color you'd feed back in as a target if you just want to recolor the dominant zone.
The workflow it unlocks
The README's Workflow D: load image β SAM/rembg to isolate the product β this node β MultiZone Recolor with the zone config. The twist is that the zone masks are numbered by k-means, not by your intent, so your zone_config mapping has to match what the clusterer actually produced - check the info output first, then write the config. And because k-means is sensitive to the starting clusters, rerunning can reshuffle which number means "body" vs. "stripes"; don't bake index meanings into a saved workflow and expect them to survive an image change.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/benjamin-bertram/ComfyUI-Recolor
cd ComfyUI-Recolor
pip install -r requirements.txt
Restart ComfyUI, or install from Manager by searching "ComfyUI-Recolor". No models to download - the segmentation weights live in your companion node pack (Impact Pack for SAM, or rembg), not here.
Honest recommendation: use this when you're processing a large set of similar product photos where manual SAM clicks would eat your afternoon, and check the info string before trusting the masks. For one hero image, the two minutes of SAM clicks still beats debugging which cluster is the logo.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | β | |
| product_mask | MASK | β | |
| num_zones | INT | 32β10 | β |
Outputs (9)
| Name | Type | Description |
|---|---|---|
| z0 | MASK | β |
| z1 | MASK | β |
| z2 | MASK | β |
| z3 | MASK | β |
| z4 | MASK | β |
| z5 | MASK | β |
| z6 | MASK | β |
| z7 | MASK | β |
| info | STRING | β |