Nodes/ComfyUI-CustomNodePacks/Layer Effect: Gradient Map (MEC)
ComfyUI Node

Layer Effect: Gradient Map (MEC)

Recolour by luminance with a three-stop ramp

By Code2Collapse·Created 7 months ago·Updated 2 days ago· 56
Layer Effect: Gradient Map (MEC)
  • image
  • layer_mask
  • image
  • effect_mask
  • report
start_color#015A52
mid_color#02AF9F
end_color#7FFFEC
mid_point0.60
opacity100

What a gradient map is

Photoshop's oldest colour trick: throw away the colours in an image and rebuild them from brightness. Bright pixels get the ramp's bright end, dark pixels get the dark end, and everything between gets a stop in between. Two stops gives you a duotone. Three stops - which is what this node gives you - gets you a decent teal-to-cyan-to-pale look, a sepia, a heat map, or a stylised poster in one node.

It's a styliser, not a corrector, and it's deterministic: no model, no VRAM, no seed lottery. That matters more than it sounds, because the alternative way people achieve this in ComfyUI is an img2img pass at high denoise, which changes everything you didn't want changed and costs a render. The KB's post-processing argument in one line: reach for the millisecond deterministic operation, not the diffusion pass.

This is one of eight layer effects in this pack ported torch-native from chflame163's ComfyUI_LayerStyle. Upstream is a very large pack with a very long dependency list and some API-calling nodes, which is why a smaller standalone port of the useful eight is a reasonable thing to exist.

How it works - including the bit that surprises people

Three stops: start_color (dark end), mid_color, end_color (bright end), with mid_point deciding where the middle stop sits on the luminance range (default 0.6, so the mid stop is past the halfway point - this biases the ramp toward the bright side, which is usually the flattering direction for a portrait).

The ramp is baked into a 256-entry lookup table, the image's luminance is computed per pixel, and the table is indexed with it.

Then the detail the tooltip doesn't tell you: the mapped colour is mixed back weighted by the source pixel's own luminance - bright pixels take nearly all of the gradient's colour, dark pixels keep most of the original. So this isn't a hard LUT replace; shadows stay anchored to the source while highlights take the ramp. That's why it looks like a grade rather than a posterise, and why setting mid_point low doesn't give you the flat two-tone you might have been after.

Finally opacity blends the whole thing over the original (100 = full effect, 0 = no effect - a clean A/B toggle), and the result is masked: if you connect layer_mask it's applied only there, and if you don't, the node uses a full-frame mask and grades the whole image. That's a genuine difference from its siblings in this pack, which require a matte.

Inputs

  • image - the source. Luminance is computed with Rec.601 weights (0.299 R / 0.587 G / 0.114 B).
  • start_color / mid_color / end_color - hex, defaults are a teal set that reads nicely as a starting point.
  • mid_point - 0–1, default 0.6. Where the middle stop lands on the luminance axis.
  • opacity - 0–100.
  • layer_mask (optional) - matte to confine the remap. No invert_mask widget on this one, so if you need the opposite region, invert the mask upstream.

Outputs: image, effect_mask, report. Note the effect_mask contract here: it's the resolved layer mask when connected, and full frame when not - so on an unmasked gradient map you get a solid white mask out, which is worth knowing before you wire it into a composite and wonder why everything changed.

Recipes

  • Duotone for a stylised poster: near-black start, mid and end in two tints of the same hue, mid_point 0.5, opacity 100. This is the closest you'll get to flat two-tone out of this node.
  • Cinematic teal-and-orange: start #0B1A2A, mid #3E4A57, end #F0C08A, mid_point 0.65, opacity 50–70.
  • Fake a thermal/heat map: black to red to yellow with mid_point 0.4.
  • Confine it: wire your subject matte into layer_mask and you're grading a person while leaving the background alone, which is the thing this node does that the flat Colour Overlay can't.

Ordering: put a gradient map after your exposure and colour match, and before grain. Grading after a gradient map tends to undo it; grain after it keeps the ramp clean.

Install

ComfyUI Manager → search "CustomNodePacks", or:

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

Restart ComfyUI and check for the pack's console load line. Pack dependencies are opencv-python, scipy, safetensors; this node is tier 1 and needs none of them specifically. And the README's standing instruction: don't pip install -r requirements.txt wholesale - it lists libraries ComfyUI already bundles and you can break your torch install doing it.

Common issues

  • The shadow areas barely changed. That's the luminance weighting described above; the ramp takes hardest on the bright end. Push opacity, or lift the image's shadows before the gradient map.
  • It's washed out. opacity under 100 blending over a colourful original. Either go to 100 for a committed look or desaturate the source first.
  • It recoloured the whole frame when you wanted one region. No mask connected. Wire layer_mask.
CategoryMEC/LayerEffects

Inputs (7)

NameTypeDefaultDescription
imageIMAGESource image to remap by luminance.
start_colorSTRING#015A52
mid_colorSTRING#02AF9F
end_colorSTRING#7FFFEC
mid_pointFLOAT0.600–1
opacityINT1000–100
layer_maskoptMASK

Outputs (3)

NameTypeDescription
imageIMAGE
effect_maskMASK
reportSTRING