Mask Or Image To Weight
Turn a batch into a number schedule
- images
- masks
- FLOAT
- STRING
This node converts pictures into numbers. Give it a batch of masks or images and it reads the mean value of each one and returns those as a list of weights - one number per frame. That sounds abstract until you're doing scheduled animation, where the whole game is producing a value-per-frame curve to drive something like IPAdapter strength, a prompt-travel weight, or an AnimateDiff schedule. Instead of typing a curve by hand, you can draw it as an animated mask and let this node read it off.
It's part of KJNodes, kijai's utility pack, and it sits in the "weights" family alongside the schedule-conversion tools you'd wire it into.
How it works
For each item in the batch, it takes the mean - the average brightness across the whole frame, on a 0-to-1 scale. A fully white mask reads 1, black reads 0, half-lit reads 0.5. Run that over a batch where the mask gets brighter and darker across frames and you get a rising-and-falling weight curve. The key thing to internalize: it's the mean over the entire frame, so it's a global brightness value, not anything spatial. Where the white is doesn't matter - only how much of it there is.
The inputs and outputs that matter
- output_type - the one required setting. list is what you want for feeding schedule/weight inputs; string is handy for eyeballing the values; tensor and pandas series are for downstream math.
- images and masks - both optional; connect whichever you have. A mask is the usual input because it's easy to animate brightness deliberately.
Outputs are a FLOAT (the weights) and a STRING (the same values as text, for preview or logging). Wire the FLOAT into whatever consumes a per-frame value; drop the STRING onto a text preview when you want to see the actual curve.
Installing it
ComfyUI Manager → search KJNodes for ComfyUI → install → restart. Manual: cd ComfyUI/custom_nodes && git clone https://github.com/kijai/ComfyUI-KJNodes, then pip install -r ComfyUI-KJNodes/requirements.txt, and restart.
Where people get burned
- Expecting spatial meaning. A half-white mask gives 0.5 no matter where the white is. If you wanted regional weighting, this isn't the node - it collapses each frame to a single average.
- Connect one input. Both
imagesandmasksare optional, which means it's on you to actually wire one of them; leave both empty and there's nothing to average. - Wrong output type downstream. If the next node rejects the connection, you've probably got
tensorwhere it wanted alist. Setoutput_typeto match what the consumer expects - and if you're chaining into another schedule node, its sibling Weight Schedule Convert exists precisely to bridge those types.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| output_type | COMBO | list | 4 options: list, pandas series, tensor, string |
| imagesopt | IMAGE | — | |
| masksopt | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| FLOAT | FLOAT | — |
| STRING | STRING | — |