Vapoursynth VerticalBandDeflicker

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

VerticalBandDeflicker removes vertical brightness bands that change over time – the column-wise density flicker of old film scans, where a light or dark stripe runs through the whole frame height and drifts or pulses from frame to frame. Grain and fine detail are kept.

Filtering → Vapoursynth → Frame → Stabilize

VerticalBandDeflicker controls in Hybrid
VerticalBandDeflicker controls in Hybrid

What it does

For every frame VerticalBandDeflicker builds a reference from its neighbor frames: the median of the frames radius × step before and after it (the current frame itself is left out). With motion compensation the neighbors are first aligned onto the current frame, so camera and actor motion do not count as bands. The difference between frame and reference is measured per column and per horizontal strip; pixels that differ by more than Motion threshold are treated as motion and ignored. The resulting band profile is smoothed, everything wider than Max. band width is left alone, and the rest is subtracted from the luma as a smooth correction (at most Limit). Chroma is copied.

Neighbors behind a scene change or before the start / after the end of the clip are replaced by their counterpart on the other side, so the reference never mixes two scenes.

Settings

The controls are grouped into Reference (how the comparison frame is built), Measurement (how the bands are found) and Correction (how much is removed).

Control Parameter Range / values Hybrid default Meaning
Reference
Radius radius 1 – 12 12 Neighbor frames on each side that form the reference.
Step step 1 – 2 2 Distance between those neighbors; 2 doubles the reach (±24 frames with radius 12) at the same cost. Bands that last longer than the reach stay.
Scene scthresh 0 – 1 (step 0.01) 0.1 Scene change threshold; the reference does not reach across a scene change.
Motion compensation mc on/off on Aligns the neighbors with motion vectors before the reference is formed. Needed whenever the camera or actors move.
thSAD thsad 0 – 10000 2000 Blocks whose compensation error exceeds this are rejected (the current frame is used instead). Grainy film needs high values; too low leaves the bands in the reference. Only with motion compensation.
Measurement
Analysis width width 16 – 3840 480 Width of the scaled copy the bands are measured on; the correction is applied at full resolution.
Strips strips 1 – 32 6 Horizontal strips measured separately, so a band may drift sideways along its height.
Smooth smooth 0 – 50 2 Horizontal smoothing radius of the band profile (analysis pixels).
Max. band width maxwidth 2 – 2000 150 Profile structure wider than this (in pixels of the analysis copy, 150 ≈ 600 px at 1920 width) is left to a global deflicker.
Motion threshold motion 0 – 255 (step 0.5) 10 Pixels that differ from the reference by more than this count as motion and are left out of the measurement (8-bit scale).
Correction
Strength strength 0 – 4 (step 0.1) 1 Factor on the measured band profile; below 1 the bands are only weakened.
Limit limit 0 – 255 (step 0.5) 8 Maximum correction per pixel (8-bit scale).
Debug debug off, correction, measurement mask, difference off Shows what the filter measures instead of the filtered clip, see Debug views. The view replaces the output, so switch it off for the encode.

Debug views

With Debug the filter returns a view of its analysis instead of the filtered clip. The view has the format of the input; only the luma carries the view, chroma is neutral (gray). Corrections and differences are shown 10 times stronger around mid gray.

Debug Shows Helps with
correction The band profile that gets subtracted. Light = a light band is darkened, dark = a dark band is brightened. Judging Limit and Strength: stripes in places without visible bands mean too much is corrected; bands that stay visible but show here as weak mean they are capped or outside the reach.
measurement mask White = pixels that are measured, black = pixels that count as motion and are left out. Setting Motion threshold: moving people and objects should be black, the still background white. If a lot of the background is black, raise Motion threshold or check thSAD.
difference The difference of each frame to its temporal reference, before the motion mask. Seeing bands and motion together. A band that does not show here is part of the reference (it lasts longer than the reach). Flat mid gray areas are where the motion compensation rejected the neighbor frames.

The same views are available in scripts as stabilize.VerticalBandDeflickerMask(clip, mode=1..3, scale=10, …); it takes the same parameters as the filter, scale sets the amplification.

Example

Default settings:

# removing vertical luma bands using VerticalBandDeflicker
clip = stabilize.VerticalBandDeflicker(clip, tools={'mv': 'mvgpu', 'expr': 'akarin', 'scd': 'scd'})

Motion compensation off and a shorter reference:

clip = stabilize.VerticalBandDeflicker(clip, radius=6, step=1, mc=False, tools={'mv': 'mvgpu', 'expr': 'akarin', 'scd': 'scd'})

Debug view of the measurement mask:

clip = stabilize.VerticalBandDeflicker(clip, debug=2, tools={'mv': 'mvgpu', 'expr': 'akarin', 'scd': 'scd'})

How Hybrid calls it

  • VerticalBandDeflicker works on gray and YUV clips, 8–16-bit integer and 32-bit float; RGB is converted to YUV first.
  • Values are only written when they differ from the defaults; thsad is only written with motion compensation, Debug is written as debug 1 – 3.
  • The Tools group selects the motion-vector plugin (mvutensils, mvgpu, mvtools), the Expr plugin (akarin or cranexpr; std.Expr can not be used) and the scene change detection. The motion-vector selection is only enabled with Motion compensation.
  • Frame count and frame rate do not change.
  • VerticalBandDeflicker also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

Tips

  • Use Deflicker in front of it: it removes the global brightness flicker, VerticalBandDeflicker only the part that differs between columns. In tests the leftover bands were about half as strong with Deflicker in front.
  • Bands that last longer than the reach of the reference are seen as picture content; at the very start of a clip there are no earlier frames, so a band over the first frames is only partly removed.
  • Frames with very strong changes (e.g. a dissolve at a cut) can not be compensated and stay uncorrected.
  • Where people move, the correction can contain short stripes; lower Limit or Strength if they show.
  • Thin stripes: with the defaults the filter sees bands from about 10–20 px width on (the analysis copy has 4 px per pixel at 1920 width, Smooth widens that further). For thin flickering stripes of 2–8 px set Analysis width 1920, Smooth 1 and Max. band width 600 (the same limit in pixels of the full-width copy). In tests this halved the thin stripes, but the filter got about seven times slower.
  • Wide bands at the picture edge are only partly caught: near the edge most of what Max. band width averages is the band itself, so it counts as wide structure. A larger Max. band width helps somewhat.
  • Flickering lines that are not brightness: vertical edges (curtain folds, posts) that move sideways by a fraction of a pixel from frame to frame look like flickering lines as well. VerticalBandDeflicker can not remove that; it is residual jitter (see Stab).
  • DescratchHighPass decides on every frame anew and can itself cause flickering lines on such edges; its temporal check (Temporal radius 2) prevents that.

For global brightness flicker see Vapoursynth Deflicker and Vapoursynth SmallDeflicker; for per-pixel shimmer see Vapoursynth ReduceFlicker; for thin vertical scratches see Vapoursynth DeScratch and Vapoursynth DescratchHighPass.

Sources