Nodes/ComfyUI-CustomNodePacks/Luminance Keyer — Highlights / Shadows / Custom
ComfyUI Node

Luminance Keyer — Highlights / Shadows / Custom

Nuke's LumaKeyer inside ComfyUI, no model required

By Code2Collapse·Created 6 months ago·Updated a day ago· 52
Luminance Keyer — Highlights / Shadows / Custom
  • image
  • mask
  • info
modeauto
low0.00
high1.00
gamma1.00
falloff1.0
invertfalse

You don't need a segmentation model to mask the sky, the blown-out highlight, or the shadowed corner of a frame. You need brightness. Luminance Keyer (MEC) is a faithful port of Nuke's LumaKeyer - convert the image to luminance, threshold a brightness range, get a matte. Pure tensor math, no weights, no VRAM pressure, instant on a batch of frames.

If you've ever been told to "just use SAM" for a sky replacement and thought that was absurd overkill, this is the node that validates you.

How it works

It computes ITU-R BT.709 luminance - 0.2126R + 0.7152G + 0.0722B - then keys a brightness range with a Hermite smoothstep falloff so the matte edge is a soft S-curve instead of a hard line. The mode dropdown is where you live:

  • highlights (0.7–1.0), midtones (0.3–0.7), shadows (0.0–0.3) - fixed ranges.
  • custom - uses the low/high sliders directly.
  • auto (default) - measures mean luminance and picks the minority range: a bright image keys the shadows, a dark one keys the highlights, a balanced one keys the midtones. It's a decent guess for a first pass; you'll usually switch to custom after that.

The knobs that actually matter:

  • falloff - edge softness. 0 is a hard binary edge, 1 is the classic smoothstep, >1 gets very gradual. This is the difference between a key that looks like a mask and one that looks like a matte.
  • gamma - applied after keying. >1 shrinks the mask toward black, <1 expands it. When the key has the right shape but the wrong coverage, reach for gamma, not the thresholds.
  • invert - flip keyed and unkeyed.

Outputs: mask (the matte, MASK type) and info - a JSON string reporting the mode and thresholds actually used, which is a lifesaver when auto picked something and you need to know what.

Where you'd actually use it

The classic cases: sky replacement (key the highlights, feed the mask to a composite), pulling a highlight matte for selective grading, or building a shadow mask to drive a darkening pass. It's also genuinely useful as a pre-stage in this pack's bigger nodes - MaskOpsMEC can run an internal luma key as a hint before segmentation. Because it's pure tensor math, it processes a whole video batch without sweating, which makes it the cheap temporal mask source that the video nodes (MaskTracker, MaskTemporal) are happy to consume.

One limitation worth knowing: luminance keys struggle when foreground and background share brightness - that's the "color confusion" case, and no brightness threshold fixes it. That's what the neural matters in this pack are for.

Install

Standard pack install:

cd ComfyUI/custom_nodes
git clone https://github.com/Code2Collapse/ComfyUI-CustomNodePacks.git

or ComfyUI Manager → search "CustomNodePacks", restart, and look for the [MEC] Loaded ... line in the console. No extra dependencies - the docstring explicitly notes "pure tensor math. No cv2 or model dependencies." If a mask comes back fully white or fully black, check invert and remember low/high are only honored in custom mode; presets silently override them, which trips people up the first time.

CategoryC2C/Keying

Inputs (7)

NameTypeDefaultDescription
imageIMAGEInput image(s) to extract luminance key from.
modeCOMBOautoPreset luminance range or custom thresholds. auto: Analyzes image brightness to pick best range. highlights: Keys bright regions (0.7–1.0). midtones: Keys mid-range luminance (0.3–0.7). shadows: Keys dark regions (0.0–0.3). custom: Uses the low/high sliders directly.
lowFLOAT0.000–1Low threshold – pixels with luminance below this become 0 in the mask. Only used directly in custom mode; presets override this.
highFLOAT1.000–1High threshold – pixels with luminance above this become 1 in the mask. Only used directly in custom mode; presets override this.
gammaFLOAT1.000.01–10Gamma correction applied after keying. >1 compresses mask toward black (reduces coverage). <1 expands mask toward white (increases coverage).
falloffFLOAT1.00–10Smoothness of the transition between low and high thresholds. 0 = hard binary edge. 1 = standard smooth. >1 = very gradual transition.
invertBOOLEANfalseInvert the output mask (swap keyed and unkeyed regions).

Outputs (2)

NameTypeDescription
maskMASKLuminance-based matte for the chosen brightness range.
infoSTRINGJSON summary of effective mode and thresholds used.