Get Mean Color (Gayrat)
The average color of an image, in every format you'd want
- image
- mask_opt
- int
- red
- green
- blue
- hex
Sometimes the thing you need from an image isn't the image - it's its dominant color. Get Mean Color computes the average RGB of whatever you feed it and hands it back in every format a downstream node could want: a packed integer, separate red/green/blue channels, and a hex string. It's a fork of ALatentPlace/ComfyUI_yanc with one non-working node cut out (the author says so in the README - "the node didn't fully run for me, so I removed one node").
Where does that actually get used? Matching colors across a workflow. Grab the mean color of a reference image and drive an overlay, a background, a tint, or a color-match step from it. Feed it a masked region and you get the average color of just that area - say, the background behind a subject - which is the sort of thing you want when you're harmonizing a composited image with its surroundings. It's a tiny deterministic primitive, the kind of thing post-processing workflows chain dozens of, and it does one job cleanly.
Inputs
- image - required.
- amplify (boolean, default off) - boosts the result: the brightest RGB channel is scaled up to 255 and the others are raised proportionally, so the hue stays identical but the color gets punchier. The README's worked example: mean (100,150,200) → amplified (128,191,255).
- mask_opt (optional) - if provided, the mean is computed only over the masked pixels. Mask and image must match in spatial dimensions or it raises an error.
Outputs
- int - the RGB value packed as one integer (
0xRRGGBB). - red, green, blue - each channel as 0–255 INT.
- hex - a
#RRGGBBSTRING.
Take whichever format your next node wants. Color inputs around ComfyUI are usually hex strings or individual ints, so you're covered either way.
Honest notes
Amplify is a real behavior, not a gimmick - with a mid-grey image it turns a washed-out average into a saturated color you can actually use as a background, while keeping the hue. But remember it's mean, not dominant: a dark scene with a small bright window averages to something darker than your eye would call the "main" color. If you want the perceptual dominant color, you need a histogram/top-color node from a bigger image-utility pack, not this one. And the mask_opt path multiplies the image by the mask, so a soft-edged mask weights pixels by their alpha rather than doing a hard in/out average - worth knowing if your mask is feathered.
Install
ComfyUI Manager: search ComfyUI_Gayrat. By hand:
cd ComfyUI/custom_nodes
git clone https://github.com/gayratv/ComfyUI_Gayrat
cd ComfyUI_Gayrat
pip install -r requirements.txt
Restart ComfyUI; find it under Gayrat/images. No extra downloads - plain torch math. It ships in a small personal grab-bag pack, so expect the occasional rough edge and lean on the source when something's unclear.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| amplify | BOOLEAN | false | — |
| mask_optopt | MASK | — |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| int | INT | — |
| red | INT | — |
| green | INT | — |
| blue | INT | — |
| hex | STRING | — |