anubhavmalhotra / vibing / eyeglass-glare-removal.md

Taking the glare out of glasses on video

2026-11-25 · 5 min read · anubhavmalhotra/eyeglass-glare-removal

Wear glasses on camera and sooner or later you get the look: two bright rectangles where your eyes should be. It's the laptop screen, reflected in the lenses, and it lands on the one part of the frame everyone is looking at.

The usual fixes all happen before you hit record: tilt the frames, move the lamp, dim the screen, or buy anti-reflective lenses, which trade white glare for a green or violet sheen. eyeglass-glare-removal is the fix after the fact. It takes a talking-head video and repaints only the glare, and leaves the eyes, the blinks and the frames alone.

See it first

The four frames below are drawn, not filmed. A drawing has one advantage over footage: the clean version exists, so you can check exactly what should come back. The glare masks and the paste-back are the package's own code, run on these drawings. The one stand-in is the repainting: where the real pipeline asks a video model to fill in the glare, these use the clean drawing.

Tap the labels to switch views. changed marks in red every pixel that differs between before and after; the green line is the lens.

After: both eyes clearly visible through black acetate glasses, with no reflection. Before: a pale blue rectangle, the reflection of a laptop screen, covers each eye behind black acetate glasses. What changed: a red patch over each screen reflection, inside the green lens outlines. The frames and the face around them are not marked.
A laptop screen, black acetate frames. The reflection hides both irises. 5.8% of the frame changes, all of it inside the lenses.
After: round gold wire glasses with clear lenses and both eyes visible. Before: a bright orange lamp reflection with a white core sits on the upper half of each eye, behind round gold wire glasses. What changed: a small red patch over each lamp reflection. The thin gold rims are not marked.
A warm desk lamp, thin gold wire frames. A bright metal rim looks a lot like glare, and the compositor keeps it out of the edit. 3.8% of the frame changes.
After: tortoiseshell glasses with clear lenses and no colored tint. Before: a green tint over the lower half of each lens and a violet arc along the top, behind tortoiseshell glasses. What changed: red over the green patch and the violet arc in each lens. The mottled frames are not marked.
An anti-reflective coating, tortoiseshell frames. Colored glare is judged against skin measured just outside the lenses, not against fixed colors. 12% of the frame changes.
After: rimless glasses with both eyes clearly visible. Before: rimless glasses. The left lens is clear; the right lens shows a bright four-pane window over the eye. What changed: red only over the window reflection in the right lens. Nothing in the left lens is marked.
A window in one lens, rimless frames. The other lens has no glare, so not one pixel of it changes.

Across all four, the detector flagged nothing on the clean drawings, and not one pixel of rim, brow or skin outside the lenses changed.

Why it's hard

Glare isn't noise you can filter out. Under a screen reflection the iris is simply missing, so it has to be drawn again, and drawn the same way in every frame or it flickers. It has to keep the blinks that happened and not invent ones that didn't. And whatever it doesn't fix, it mustn't touch: a tool that softens the whole face to fix two lenses has made the video worse.

So the pipeline narrows in. SAM2.1 finds and tracks the lenses, a detector finds the glare inside them, a video inpainting model (Wan2.1-VACE) repaints just that, and a compositor puts it back. The README goes stage by stage.

Showing the model your eyes

The inpainting model can be shown a clean look at the person's eyes, and the video usually has one somewhere. The pipeline scans every frame for glare and picks the cleanest. If no single frame is clean, it can join a clean left eye from one frame with a clean right eye from another, or mirror the one clean eye across the nose. You can also hand it a photo.

The rule it doesn't break: a frame with glare is never passed off as clean. If nothing qualifies, it inpaints without a reference rather than teach the model the glare.

The bake-off: bigger wasn't better

The model was picked by running the candidates on the same five-second clip, with heavy screen glare and a warm lamp.

The smallest model won, and the most useful lesson was that the negative prompt does real work: switch it off and the glare comes back. The numbers are in the benchmarks.

Leaving everything else alone

The last step is what makes this usable, and its job is mostly saying no. The compositor only edits near detected glare, so a clean lens, or a whole clean frame, passes through untouched. It shields the rims, whether dark acetate, bright wire or tortoiseshell, because a rim is exactly the kind of thin, high-contrast edge a model likes to smear. Outside the edit, every pixel is the original, bit for bit, until the final encode. That's what the changed views above show.

The honest part: it's slow

On our NVIDIA DGX Spark, an 87-second talking-head clip took a little over three hours, nearly all of it inpainting: about four seconds of GPU per output frame. Tracking the lenses took eight minutes, and everything else took seconds. It's an overnight job, not a live filter, and it's built for that: every stage checkpoints and resumes, and a five-second --preview run tells you whether the full run is worth it.

The Spark had one surprise. On its Blackwell GPU, one of PyTorch's attention kernels can quietly return wrong results, with no error, just bad output. The package switches that kernel off whenever it runs on CUDA.

The source is at github.com/anubhavmalhotra/eyeglass-glare-removal (Apache-2.0), and the README walks through install and the preview workflow. Questions or ideas? The contact links are on the front page.