Nodes/ComfyUI-MAINodes/Snap: Keep eye colour
ComfyUI Node

Snap: Keep eye colour

Putting iris colour back after a redraw

By matlowai·Created 4 months ago·Updated 4 days ago· 267
Snap: Keep eye colour
  • images
  • masks
  • reference
  • reference_mask
  • images
  • report
◄strength1.00►

You redrew a take - a stage-2 pass, an upscale, a v2v clean-up - and the character's eyes changed colour. Brown went grey. Amber went olive. Nobody asked for that.

It's a known failure of redrawing: the model re-synthesises iris colour from its own prior instead of from your reference, and eyes are where diffusion is least trustworthy - "wrong eyes" has been the first photorealism tell for years. The ecosystem's answer to consistency shifted from "generate it again and hope" to "generate once, then edit that"; this is that idea narrowed to one feature. It doesn't redraw - it moves hue, and that's all.

How it works, mechanically

You hand it frames, a mask per frame, the Cast's front picture and a mask for that. It converts to CIE Lab and touches a and b only - chroma. Lightness never moves.

Each frame's iris median a/b is compared to the Cast's, and the pixels shift by (target − current) × strength. Every frame is matched to the same target, so drift across a clip gets pulled back to one colour instead of accumulating.

The fiddly part is where it's allowed to touch:

  • The mask has to look like a pair of eyes: exactly two blobs by column count, each within 4× the other's size. Profiles, backs of heads and single eye-shaped things pass through untouched.
  • The mask is eroded about a pixel per 832 px of the short side, and iris pixels next to anything bright take no shift - the fix for an orange halo at the sclera edge.
  • The shift is weighted by lightness: zero at L 22, full by L 42, zero again from 60 to 75. So pupil and outline keep their values at the bottom of the ramp, sclera and highlights at the top - colour grafted onto the lit iris, not a flat recolor, and a zero-weight pixel comes out exactly as it went in.

Frames that fail any of that come back untouched; a Cast iris that's grey (chroma under 6) skips the whole step rather than inventing a colour.

Inputs and outputs

Five inputs, all required. images are the frames (or one still); masks their irises, one per frame. reference is the Cast front picture and reference_mask its irises. strength is how far toward the Cast's colour you go - 1 all the way, 0 a useful no-op for an A/B.

Two outputs. images is the corrected frames - into Save Video / Preview, or back into whatever made the take. report is a JSON string and it's why this node is usable at all:

{"target": {"a": 18.4, "b": 22.1, "chroma": 28.7, "pixels": 214},
 "strength": 1.0, "frames": 96, "touched": 91, "mean_shift": [4.1, -6.8],
 "skipped": null, "per_frame": [...]}

Every frame not touched says why: no iris found, mask too big, not a pair, too few readable pixels. Send it to a text node before assuming the node did nothing.

Getting the masks right

Irises come from ComfyUI's core SAM3_Detect with SAM 3.1 (sam3.1_multiplex_fp16), driven by text prompts rather than clicks. The pack ANDs two of them - something like eye:2 at 0.6 with pupil:2, iris of the eye:2 at 0.3 - because on stylised faces "pupil" is often the whole iris disc, and the second prompt fills in where you've only got the dark centre.

The trap: masks needs one mask per frame, and each must contain both irises as two separate blobs, because the pair test runs on a single mask slice. Two masks per frame, one per eye, gets rejected as "not a pair of irises". It's also a per-frame loop in Python: a 192-frame take is 192 iris reads.

Install

Manager, search ComfyUI-MAINodes, or:

cd ComfyUI/custom_nodes
git clone https://github.com/matlowai/ComfyUI-MAINodes

Restart, and look under MAINodes/snap. Unlike the pack's Cut node, this one needs no ffmpeg - it's pure torch over the frames you hand it. It does need the SAM 3.1 checkpoint on disk for the masking half, and SAM 3 ships under Meta's own SAM Licence, not the old Apache one. Worth a read for commercial work.

Troubleshooting

It did nothing, and the output is byte-identical. Read report.skipped. The most common one is your Cast reference: the Cast's iris is grey (chroma 3.2 < 6): no colour to keep. A grey-eyed character can't donate a hue - use a coloured reference, or accept it.

Half the frames are untouched. Turnarounds. It only acts on a face toward camera, so profiles and backs legitimately pass through.

The hue is right but the eyes are still wrong. Design limit: hue only, lightness never. If the redraw made the iris darker, this won't relighten it - the pack says outright that anything past hue hasn't been ruled on. And try strength 0.5 instead of 1.0: pulling straight to the target median can read flatter than the original shading.

"Too big for irises." Your mask is over 2% of the frame, which means SAM grabbed a face or a head, not two irises. Tighten the prompts or cut the mask down.

Run it on the still first. It works on a single image as happily as a video. One frame at strength 1.0, eyes at 200%, then decide if the full take is worth it.

CategoryMAINodes/snap

Inputs (5)

NameTypeDefaultDescription
imagesIMAGEthe frames
masksMASKSAM3 Detect on the frames, one mask per frame: the irises
referenceIMAGEthe Cast front picture
reference_maskMASKSAM3 Detect on the Cast front: its irises
strengthFLOAT1.000–1how far toward the Cast's colour: 1 = all the way

Outputs (2)

NameTypeDescription
imagesIMAGE—
reportSTRINGJSON: the target, every frame touched or why not, the mean shift, or why it skipped