Luminance Keyer — Highlights / Shadows / Custom
Nuke's LumaKeyer inside ComfyUI, no model required
- image
- mask
- info
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 thelow/highsliders 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 tocustomafter 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.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Input image(s) to extract luminance key from. | |
| mode | COMBO | auto | Preset 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. |
| low | FLOAT | 0.000–1 | Low threshold – pixels with luminance below this become 0 in the mask. Only used directly in custom mode; presets override this. |
| high | FLOAT | 1.000–1 | High threshold – pixels with luminance above this become 1 in the mask. Only used directly in custom mode; presets override this. |
| gamma | FLOAT | 1.000.01–10 | Gamma correction applied after keying. >1 compresses mask toward black (reduces coverage). <1 expands mask toward white (increases coverage). |
| falloff | FLOAT | 1.00–10 | Smoothness of the transition between low and high thresholds. 0 = hard binary edge. 1 = standard smooth. >1 = very gradual transition. |
| invert | BOOLEAN | false | Invert the output mask (swap keyed and unkeyed regions). |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| mask | MASK | Luminance-based matte for the chosen brightness range. |
| info | STRING | JSON summary of effective mode and thresholds used. |