Vapoursynth DescratchHighPass: Difference between revisions

From wiki.selur.net
Jump to navigation Jump to search
Temporal check: how Hybrid calls it (via update-page on MediaWiki MCP Server)
MV tool field follows Temporal radius (via update-page on MediaWiki MCP Server)
 
(3 intermediate revisions by the same user not shown)
Line 13: Line 13:
# The difference DeScratch made is divided by ''Gain'' again and added to the original luma, capped by ''Limit''. Chroma is copied.
# The difference DeScratch made is divided by ''Gain'' again and added to the original luma, capped by ''Limit''. Chroma is copied.


DeScratch decides on every frame anew whether a vertical structure is a scratch. On pictures with many vertical edges (curtain folds, posts) these decisions change from frame to frame, and the changing corrections show up as flickering thin lines. The optional '''temporal check''' (''Temporal radius'' above 0) prevents that: each correction is compared with the median of the motion-compensated neighbor frames, and it is applied fully only where the pixel differs from that median in the same direction by at least 1/''Temporal factor'' of the correction, less below. Structure that is present in the neighbor frames is therefore left alone, while a scratch that shows up on single frames is still removed.
DeScratch decides on every frame anew whether a vertical structure is a scratch. On pictures with many vertical edges (curtain folds, posts) these decisions change from frame to frame, and the changing corrections show up as flickering thin lines. The optional '''temporal check''' (''Temporal radius'' above 0) prevents that: each correction is compared with the median of the motion-compensated neighbor frames, and it is applied fully only where the pixel differs from that median in the same direction by at least 1/''Temporal factor'' of the correction, less below. Structure that is present in the neighbor frames is therefore left alone, while a scratch that shows up on single frames is still removed. Where the motion compensation rejects all neighbor frames (a cut, a dissolve), the reference is the frame itself; there the correction applies without the check.


== Settings ==
== Settings ==
Line 77: Line 77:
* Values are only written when they differ from the defaults; the passes are written as one list of (min. diff, max. width, mode) tuples.
* Values are only written when they differ from the defaults; the passes are written as one list of (min. diff, max. width, mode) tuples.
* ''tr'', ''tfactor'' and ''thsad'' are only written with a temporal radius above 0; ''Temporal factor'' and ''thSAD'' are only enabled then.
* ''tr'', ''tfactor'' and ''thsad'' are only written with a temporal radius above 0; ''Temporal factor'' and ''thSAD'' are only enabled then.
* The ''Tools'' group selects the Expr plugin (akarin, cranexpr or std; a temporal radius above 1 needs akarin or cranexpr), the box blur (vszip or std) and, for the temporal check, the motion-vector plugin.
* The ''Tools'' group selects the Expr plugin (akarin, cranexpr or std; a temporal radius above 1 needs akarin or cranexpr), the box blur (vszip or std) and, for the temporal check, the motion-vector plugin (only enabled with a temporal radius above 0).
* Frame count and frame rate do not change.
* Frame count and frame rate do not change.
* DescratchHighPass also offers the [[Vapoursynth common filter options|common options]] (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).
* DescratchHighPass also offers the [[Vapoursynth common filter options|common options]] (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).
Line 85: Line 85:
* 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.
* 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.
* Real vertical structure that looks like a scratch (folds, poles) is only weakened by ''Limit''; lower it if such detail loses contrast.
* '''Bright scratches stay visible:''' ''Limit'' also caps the correction of real scratches. With the default 4 a scratch that is about 12 levels brighter than its surroundings keeps two thirds of its brightness; raise ''Limit'' to 12–20 for such scratches. ''Max. width 1'' 5 also catches the dark edges that sharpened scans often show next to a scratch.
* If folds or edges start to flicker as thin lines, set ''Temporal radius'' to 2. Scratches that stay in the same place over several frames are part of the reference then and are hardly removed any more, which is why the check is off by default.
* For such a standing scratch in a clip that needs the temporal check elsewhere, use a second DescratchHighPass: ''Duplicate'' the node in the Node Editor, set ''Temporal radius'' 0 in the copy and restrict it to the affected frames with ''ApplyOnlyTo''.
* For scratches that are clearly visible, plain [[Vapoursynth DeScratch|DeScratch]] is enough.
* For scratches that are clearly visible, plain [[Vapoursynth DeScratch|DeScratch]] is enough.



Latest revision as of 08:35, 21 November 2026

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.

DeScratch decides on every frame anew whether a vertical structure is a scratch. On pictures with many vertical edges (curtain folds, posts) these decisions change from frame to frame, and the changing corrections show up as flickering thin lines. The optional temporal check (Temporal radius above 0) prevents that: each correction is compared with the median of the motion-compensated neighbor frames, and it is applied fully only where the pixel differs from that median in the same direction by at least 1/Temporal factor of the correction, less below. Structure that is present in the neighbor frames is therefore left alone, while a scratch that shows up on single frames is still removed. Where the motion compensation rejects all neighbor frames (a cut, a dissolve), the reference is the frame itself; there the correction applies without the check.

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.
Temporal radius tr 0 – 12 0 Neighbor frames on each side that form the reference of the temporal check; 0 switches the check off.
Temporal factor tfactor 0.5 – 8 (step 0.5) 2 How far a correction may go beyond the temporal reference: 1 never moves a pixel past it, higher values also let scratches go that are faintly present in the neighbor frames. Only with a temporal radius.
thSAD thsad 0 – 10000 2000 Block SAD above which the motion compensation of a neighbor frame is rejected (the current frame is used instead). Grainy film needs high values. Only with a temporal radius.

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'})

With the temporal check:

clip = artifacts.DescratchHighPass(clip, tr=2, tools={'expr': 'akarin', 'boxblur': 'vszip', 'mv': 'mvgpu'})

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.
  • tr, tfactor and thsad are only written with a temporal radius above 0; Temporal factor and thSAD are only enabled then.
  • The Tools group selects the Expr plugin (akarin, cranexpr or std; a temporal radius above 1 needs akarin or cranexpr), the box blur (vszip or std) and, for the temporal check, the motion-vector plugin (only enabled with a temporal radius above 0).
  • 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.
  • Bright scratches stay visible: Limit also caps the correction of real scratches. With the default 4 a scratch that is about 12 levels brighter than its surroundings keeps two thirds of its brightness; raise Limit to 12–20 for such scratches. Max. width 1 5 also catches the dark edges that sharpened scans often show next to a scratch.
  • If folds or edges start to flicker as thin lines, set Temporal radius to 2. Scratches that stay in the same place over several frames are part of the reference then and are hardly removed any more, which is why the check is off by default.
  • For such a standing scratch in a clip that needs the temporal check elsewhere, use a second DescratchHighPass: Duplicate the node in the Node Editor, set Temporal radius 0 in the copy and restrict it to the affected frames with ApplyOnlyTo.
  • 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