anubhavmalhotra / vibing / eyeglass-glare-removal.md
Taking the glare out of glasses on video
- eyeglass glare
- sam2.1
- wan2.1-vace
- dgx spark
- python
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.
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.
- A one-step "delighting" model (StableDelight) removed the glare by turning the lenses pitch black.
- An image editor with a glare LoRA (WindowSeat on Qwen-Image-Edit) cut the warm glare by about 70% but left a white haze where the screen had been.
- Wan2.1-VACE 14B with a 4-step speed-up was quick, but the speed-up runs without guidance, which drops the negative prompt: the list of things to avoid, glare and reflections included. It painted the reflections back in.
- The full 14B was 2.9× slower than the small model and left a milky haze low in the lenses.
- Wan2.1-VACE 1.3B removed all of the white and orange glare and kept the real blinks.
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.