Vapoursynth DeScratch

From wiki.selur.net
Revision as of 03:48, 15 November 2026 by Selur (talk | contribs) (New filter page (via create-page on MediaWiki MCP Server))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

DeScratch removes vertical scratches from film transfers, originally from old 8 mm films. On a clip rotated by 90 degrees it also removes horizontal drop-out lines from VHS captures.

Filtering → Vapoursynth → Artifacts

DeScratch controls in Hybrid
DeScratch controls in Hybrid

What it does

DeScratch works spatially, on the current frame only. It first looks for long, thin vertical extremes (lines that are darker or brighter than their neighbors), closes small gaps and checks their length and angle. Each accepted scratch is then either corrected by subtracting its blurred variation, which keeps the picture detail inside the scratch, or replaced by the mean of the neighbor pixels in the same row, which suits opaque scratches. Keep blends between the two.

Settings

Control Parameter Range / values Hybrid default Meaning
Mode (Y/U/V) modey, modeu, modev no, low (black/green/yellow), high (white/red/blue), both low / no / no Which extremes count as scratches in each plane: dark ones, bright ones or both.
min diff. luma mindif 1 – 255 5 Smallest difference between a scratch pixel and its neighbors (luma).
min diff chroma mindifuv 0 – 255 0 The same for chroma; 0 uses the luma value.
max asym asym 0 – 255 10 Largest allowed difference between the left and the right neighbor.
max gap maxgap 0 – 255 2 Largest vertical gap inside a scratch that is still closed.
width (min/max) minwidth, maxwidth odd values 1 – 15 1 / 3 Width of a scratch in pixels; min cannot be set above max.
length (min/max) minlen, maxlen 1 – 2048 100 / 2048 Length of a scratch in lines.
max angle maxangle 0 – 90 5 Largest tilt of a scratch against the vertical, in degrees.
blur blurlen 0 – 200 15 Vertical blur radius used for the detection; the frame height divided by (blur + 1) must be at least 2.
keep keep 0 – 100 % 100 How much of the original detail inside a scratch is kept.
border border 0 – 5 2 Width of the partly corrected border next to a scratch.
Window (left/right) left, right 0 – frame width 0 / 4096 Processing window in pixels (left included, right excluded); both are rounded down to even values, right is limited to the frame width, and left stays below right.
mark mark on/off off Debug view: rejected extremes gray, scratches white or black.

Example

Default settings on a 10-bit YUV 4:2:0 source:

# adjusting color space from YUV420P10 to YUV444P8 for vsDeScratch
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P8, dither_type="error_diffusion")
# scratch removal using DeScratch
clip = core.descratch.DeScratch(clip)

How Hybrid calls it

  • DeScratch only accepts 8-bit YUV 4:2:0, 4:2:2 and 4:4:4; other formats are converted first.
  • Values are passed unchanged (there is no bit-depth scaling, since only 8 bit is accepted). Each value is only written when it differs from Hybrid's default, so at the defaults the call has no arguments and the plugin's defaults apply.
  • The mode lists are written as numbers 0 – 3 (no, low, high, both).
  • For sources wider than 4096 pixels, set the right window border to the frame width.
  • DeScratch also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

The plugin

DeScratch was written by Alexander G. Balakhnin (Fizick) for AviSynth and later modernized and ported to VapourSynth by Fredrik Mellbin; one source builds both versions. Since version 2.0 (2023) it also handles 4:2:2, 4:4:4 and the chroma planes.

VHS drop-outs

The documentation shows how to remove horizontal drop-out lines: turn the clip to the left, run DeScratch with a low difference (about 4), a large gap (20), long minimum length (300), strong blur (50), no border and a maximum angle of 0, then turn the clip back.

Sources