Vapoursynth DescratchHighPass

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

DescratchHighPass removes faint vertical scratches that DeScratch alone can not separate from the film grain. It runs DeScratch on an amplified copy of the fine horizontal detail and adds only the repair back to the clip, at full bit depth.

Filtering → Vapoursynth → Artifacts

DescratchHighPass controls in Hybrid
DescratchHighPass controls in Hybrid

What it does

Faint scratches are often only one or two levels brighter or darker than their surroundings – weaker than the grain. With a low mindif DeScratch then marks grain and real edges, with a higher one it misses the scratches. DescratchHighPass works around this:

  1. It subtracts a horizontal blur (H. radius) from the luma. What is left is the fine left-to-right detail including the scratches; wide structures such as shadows, flicker and large edges are gone.
  2. It multiplies this detail by Gain and stores it as an 8-bit picture around mid gray, so a scratch of 1.5 levels becomes about 9 levels deep.
  3. DeScratch runs on that copy in one or two passes (first thin, then wider scratches).
  4. The difference DeScratch made is divided by Gain again and added to the original luma, capped by Limit. Chroma is copied.

Settings

Control Parameter Range / values Hybrid default Meaning
Gain gain 0.5 – 32 (step 0.5) 6 Amplification of the high-pass that DeScratch searches in.
H. radius hradius 1 – 64 8 Radius of the horizontal blur that is subtracted; wider structure does not reach DeScratch.
Limit limit 0 – 255 (step 0.5) 4 Largest correction per pixel (8-bit scale). Protects real vertical detail such as curtain folds.
Mark mark on/off off Shows the amplified copy with the detected scratches drawn in (luma; chroma unchanged). For tuning only.
Min. diff 1 / 2 passes (mindif) 1 – 255 4 / 4 Smallest difference of a scratch to its neighbors, measured on the amplified copy.
Max. width 1 / 2 passes (maxwidth) odd values 1 – 15 3 / 7 Largest scratch width per pass.
Mode 1 / 2 passes (modey) low (black), high (white), both both / both Dark scratches, light scratches or both.
Pass 2 passes on/off on Runs the second pass on the result of the first.
Blur length blurlen 0 – 200 100 Vertical blur DeScratch uses for the detection; long values suppress grain.
Min. / Max. length minlen, maxlen 1 – 2048 300 / 2048 Length of a scratch in lines.
Gap maxgap 0 – 255 2 Largest vertical gap inside a scratch that is still closed.
Max. angle maxangle 0 – 90 5 Largest tilt against the vertical, in degrees.
Asym asym 0 – 255 10 Largest difference between the left and the right neighbor (amplified copy); keeps edges from being taken for scratches.
Keep keep 0 – 100 % 100 How much of the detail inside a scratch is kept.
Border border 0 – 5 2 Width of the partly corrected border next to a scratch.
Min. width minwidth odd values 1 – 15 1 Smallest scratch width for both passes.

Example

Default settings:

# scratch removal using DescratchHighPass
clip = artifacts.DescratchHighPass(clip, tools={'expr': 'akarin', 'boxblur': 'vszip'})

Higher gain, only the first pass:

clip = artifacts.DescratchHighPass(clip, gain=8.0, passes=[(4, 3, 3)], tools={'expr': 'akarin', 'boxblur': 'vszip'})

How Hybrid calls it

  • DescratchHighPass works on gray and YUV clips, 8–16-bit integer and 32-bit float; unlike DeScratch it needs no conversion to 8 bit.
  • Values are only written when they differ from the defaults; the passes are written as one list of (min. diff, max. width, mode) tuples.
  • The Tools group selects the Expr plugin (akarin, cranexpr or std) and the box blur (vszip or std).
  • Frame count and frame rate do not change.
  • DescratchHighPass also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

Tuning

  • Switch on Mark and raise Gain (or lower Min. diff) until the scratches are marked; if grain or edges get marked, go the other way.
  • Real vertical structure that looks like a scratch (folds, poles) is only weakened by Limit; lower it if such detail loses contrast.
  • For scratches that are clearly visible, plain DeScratch is enough.

For long vertical brightness bands see Vapoursynth VerticalBandDeflicker; for dirt and spots see Vapoursynth SpotLess and Vapoursynth RemoveDirt.

Sources