Color Patch Flatten
Flatten a color patch to its mean — the gentle way to homogenize flat areas
- image
- mask
- OUTPUT
- ALPHA
Color Patch Flatten is the middle child of this pack's color nodes: less surgical than Achromatic Stabilizer (which only touches near-grey pixels) and less aggressive than Color Patch Merge (which clusters whole regions into solid plates). What it does is straightforward: it computes the average HSV of a patch and pulls every pixel close to that average toward it, within a tolerance. The result is a "flat color" homogenization that cleans up mottled flat areas without nuking the image into poster art.
The intended use case is dead simple - you have a region that's supposed to be one color but isn't (a wall, a sky, a background that AI rendered with slow drifting hue noise), and you want it to read as one color. Because it works in HSV with a tolerance gate, pixels that are genuinely different (the edge of a person, a shadow, a separate object) are left alone. It's the "make the flat stuff actually flat" button.
The controls that matter
- Flatten Tolerance (0–1, default 0.05) - how different a pixel's HSV value can be from the patch mean and still get pulled in. Larger number = weaker effect (the author's phrasing, and it's right: a big tolerance sweeps in more, but since it pulls toward the mean, "weak flattening" happens when you allow too much variance). Start at 0.05 and move up if you're barely seeing anything.
- Flatten H, Flatten S, Flatten V - the three booleans (labeled H, S, V on the node). Each independently toggles flattening hue, saturation, or brightness. This is the killer feature: flatten only hue to fix hue-bleeding while keeping luminosity variation, or flatten only saturation to kill color-cast noise without touching luminance. Want to remove a magenta tint without turning the image flat? Flatten H alone, or S alone, and leave V off.
- mask (optional) - restrict the analysis and flattening to a region. The mean is computed over the masked area, and the mask also limits where pixels get pulled. Combine with the outputs below for region-aware cleanup.
One implementation detail that tells you the author thought about it: hue is a circle, so the node computes hue distance the circular way (min(|h - mean|, 1 - |h - mean|)). Red sits at both ends of the hue wheel, and a naive diff would break flattening there. This one doesn't.
Outputs
- OUTPUT (IMAGE) - the flattened image.
- ALPHA (MASK) - the alpha channel, preserved/derived from your mask. Feed it onward so downstream nodes know where the change happened.
Both output nodes are non-terminating, so you can chain this into a save or a composite without extra wiring.
When to pick it over the siblings
The pack ships three color-fixers, and picking wrong wastes a couple of restarts. Quick map: near-neutral color noise → Achromatic Stabilizer. Whole-region flat-color posterization → Color Patch Merge (Smooth or Unify). One specific channel drifting in an otherwise-fine patch → Color Patch Flatten, and use the H/S/V toggles to touch only what's broken. Flatten is the one you reach for when the problem is subtle and targeted.
Install
It's part of ComfyUI-Image-Process. ComfyUI Manager → search "ComfyUI-Image-Process", or:
cd ComfyUI/custom_nodes
git clone https://github.com/wakaura-asaho/comfyui-image-process
pip install -r comfyui-image-process/requirements.txt
then restart. Dependencies are numpy, Pillow 12.1+, scipy, opencv, scikit-image - nothing exotic, no model downloads. Like everything in this pack, it's built for modern ComfyUI (frontend ≥ 1.37, base ≥ 0.12); on older installs it won't show up at all. Marked experimental in the code, so don't be shocked if the occasional edge case needs a tolerance nudge rather than a bug report.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | The image to be processed. | |
| flatten_tolerance | FLOAT | 0.050–1 | How different colors can be conisdered as a same color patch. Larger number means weaker flattening effect. |
| flatten_hue | BOOLEAN | true | — |
| flatten_saturation | BOOLEAN | true | — |
| flatten_brightness | BOOLEAN | true | — |
| maskopt | MASK | Optional alpha channel mask. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| OUTPUT | IMAGE | — |
| ALPHA | MASK | — |