03 · Scratch

Remove dust & vertical lines

Dust specks flash on for a single frame; long scratches run down the film where it dragged against something. Two different problems, two cures.

Fixes: dust + scratches Tools: RemoveDirt, DeScratch run_avs.py

The key insight for dust: a speck exists in one frame only. So take the temporal median, for each pixel, the middle value across the previous, current and next frame, and the odd-one-out speck is thrown away automatically. But that alone would erase anything genuinely moving. So RestoreMotionBlocks detects the moving blocks and copies the original pixels back into them. Finally DeScratch hunts the long vertical lines specifically.

Top: three consecutive frames, a moving head, a one-frame dust speck (only in the middle), and a scratch that persists in all three. Bottom: the output as you stack the cures.
Order rule: dust removal must run before denoise. RemoveDirt finds dirt by how much a pixel differs between frames, and denoising erases exactly those differences. Denoise first, and the dust becomes invisible to the dust remover.

DeScratch is kept deliberately conservative so it targets only thin, long, near-vertical lines and leaves real vertical structures (a doorframe, a pole) alone: maxwidth=5 (thin), minlen=100 (long), maxangle=3 (near-vertical), mindif=6 (clear scratches only).

Yossi's dials: conservative defaults, no overrides.