Nodes/zhangp365/ComfyUI-utils-nodes/Image Mask Color Average
ComfyUI Node

Image Mask Color Average

Image Mask Color Average

By zhangp365·Created 2 years ago·Updated 5 months ago· 135
Image Mask Color Average
  • image
  • mask
  • COLOR_DEC
  • COLOR_HEX

Point this node at an image and a mask, and it tells you the average color inside that masked region - nothing more, nothing less. Per the README: "calculate the average color of the image within the mask. It returns the decimal and hexadecimal values of the average color." You'd reach for this any time a downstream step needs a single representative color for a region rather than the full pixel data - sampling skin tone from a face mask, pulling a dominant background color to match a composite against, or feeding a color value into something further down the graph that expects a single value rather than an image.

It's a measurement node, not a transform. It doesn't touch your image or mask - it reads them and reports a number. That puts it in the same family as NeedImageSizeAndCount from this same pack: small, single-purpose nodes whose entire job is answering a question about an image so you can make a decision with the answer, rather than doing the image processing yourself.

Inputs: image and mask, both required, no optional parameters and no defaults to configure. You mask whatever region you care about - a face, a garment, a background patch - and the node averages every pixel that falls inside it.

Outputs: two of them. COLOR_DEC is an INT - the average color as a single decimal (packed RGB) value. COLOR_HEX is a STRING - the same color as a hex string, the format you'd want if you're piping it into a text field, a UI label, or anywhere else that expects human-readable color. Which one you use depends entirely on what's downstream: math nodes and anything expecting a numeric color value want COLOR_DEC; anything that displays or logs a color, or expects the conventional #RRGGBB-style format, wants COLOR_HEX.

Install: it's part of the same pack as everything else covered here. In ComfyUI Manager, search "ComfyUI-utils-nodes" (listed as "Some Utils for ComfyUI"). Or from the command line:

cd ComfyUI/custom_nodes
git clone https://github.com/zhangp365/ComfyUI-utils-nodes

Restart ComfyUI after either method. This node has no external dependencies beyond the base install - no models, no API keys, nothing to configure.

Where people trip up:

  • The result is only as good as the mask. A loose or feathered mask that includes background pixels alongside your subject will pull the average toward whatever's outside the region you actually meant to sample - tighten the mask if the color you're getting back looks off from what you expected.
  • This computes a flat average, not a mode or a perceptually weighted color. A region with strong lighting variation (deep shadow on one side, bright highlight on the other) will average out to something that doesn't actually appear anywhere in the source - useful for some purposes, misleading for others depending on what you're trying to match.
  • Since this node has no configuration to get wrong, if you're not seeing the outputs you expect the problem is almost always upstream - check that your mask is actually covering the region you think it is before assuming the color math is wrong.
Categoryutils/image

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
maskMASK

Outputs (2)

NameTypeDescription
COLOR_DECINT
COLOR_HEXSTRING