Avisynth DeScratch

From wiki.selur.net
Jump to navigation Jump to search

DeScratch removes vertical scratches from film scans. It is a plugin by Fizick, made for 8 mm film, and works on each frame alone.

Filtering → Avisynth → Artifacts

DeScratch controls in Hybrid
DeScratch controls in Hybrid

What it does

DeScratch searches for long, thin, vertical lines that are darker or brighter than their surroundings. It replaces each scratch by interpolating from the neighbouring pixels. keep blends a share of the original detail back into the scratch.

Typical uses:

  • Remove vertical scratches from film scans.
  • Horizontal scratches need a clip that is rotated by 90° before and after the filter; Hybrid does not rotate the clip.
  • Tune min Diff, width and length on a short sample, because loose settings can remove real picture detail.

Settings

Control Parameter Range Hybrid default Meaning
width (min/max) minwidth / maxwidth odd values 1–15 1 / 3 Width range of a scratch in pixels. The minimum cannot be larger than the maximum: raising the minimum above the maximum raises the maximum, lowering the maximum below the minimum lowers the minimum.
min Diff mindif 1–255 5 Minimum luma difference between the scratch and its neighbours.
max Asym asym 0–255 10 How different the two sides of a scratch may be.
max gap maxgap 0–255 2 Vertical gap that is closed when joining scratch parts.
length (min/max) minlen / maxlen 1–2048 100 / 2048 Length range of a scratch in pixels.
max angle maxangle 0–90 5 Largest angle from vertical in degrees.
blur blurlen 0–200 15 Vertical blur radius used for detection.
keep keep 0–100 100 Percentage of detail that is kept inside the scratch.
border border 0–5 2 Pixels around the scratch that are partly restored.
Mode Y modeY no, low (black), high, both low (black) Which scratches are removed in luma. Low is dark, high is bright.
Mode U modeU no, low, high, both no Which scratches are removed in U. Low is green, high is red.
Mode V modeV no, low, high, both no Which scratches are removed in V. Low is yellow, high is blue.
min diff UV mindifUV 0–255 0 Minimum difference for chroma. 0 uses min Diff.
Window (left/right) left / right 0–4096 0 / 4096 Picture columns in which scratches are searched. 4096 stands for the full frame width.
mark mark on/off off Debug view that marks what was detected.

Example

Default settings on a 10-bit YUV 4:2:0 source; Hybrid converts to 8 bit and back:

# descratching using DeScratch
# Converting from 10 to 8bit for DeScratch
ConvertBits(8)
DeScratch()
# Converting from 8 to 10bit for encoder
ConvertBits(10)

How Hybrid calls it

  • Hybrid loads descratch.dll and calls DeScratch().
  • The plugin accepts only 8-bit YV12 (4:2:0). Other input is converted to it first and converted back afterwards.
  • Every parameter is only written when it differs from Hybrid's default. At the defaults the call has no arguments.
  • Interlaced input is processed with SeparateFields(), DeScratch(...) and Weave(), so each field is filtered as it is.
  • The mode lists are written as the numbers 0–3 (no, low, high, both).
  • The filter works on the CPU.
  • DeScratch also offers the common options and can be added to the filter queue several times.

Background

DeScratch is by Fizick. Version 2.0 (October 2023) added the formats YV16 and YV24 and the VapourSynth version. The plugin shipped with Hybrid is an older build that accepts only YV12. The debug view is easier to read after Greyscale(), UtoY() or VtoY().

See also: Vapoursynth DeScratch

Sources

  • DeScratch (plugin and documentation)
  • Hybrid's tooltips
  • The AviSynth+ documentation does not cover DeScratch.