Vapoursynth FineDeHalo

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

FineDeHalo removes halos next to edges by running DeHalo_alpha and blending its result back only around edges, through a set of edge masks. The main line edges stay out of the mask, so lines keep their detail.

Filtering → Vapoursynth → DeHalo

FineDeHalo controls in Hybrid
FineDeHalo controls in Hybrid

What it does

A Prewitt edge mask is turned into a "strong" mask (the sharpest edges) and grown by the radius into a "large" mask. A wider "light" mask is grown, amplified and shrunk into an exclusion mask. The area that is processed is the large mask minus the strong and exclusion masks, so the halo zone beside the lines is filtered while the lines and simple detail stay untouched. Optional contra-sharpening gives back some of the sharpness the halo removal takes. Only luma is processed; chroma passes through unchanged.

Settings

Control Parameter Range / values Hybrid default Meaning
Radius (x/y) rx / ry 0.01 – 10 2 / 2 DeHalo_alpha radii, also rounded to whole pixels to grow and shrink the masks. Keep them as low as possible.
Edge threshold (min/max) thmi / thma 0 – 255 80 / 128 Edge range (8-bit scale) of the strong mask; edges above it are kept as main lines. Check with Show mask = strong mask.
Limit threshold (min/max) thlimi / thlima 0 – 255 50 / 100 Wider edge range for the exclusion zones; takes in more edges but leaves out simple detail.
Strength (dark/bright) darkstr / brightstr −10 – 10 1 / 1 DeHalo_alpha strength for dark and bright halos; for anime a dark strength of 0.4 – 0.8 can help.
Contrast sharpening contra 0 – 1 0 Contra-sharpening after the dehalo step; 0 = off, 1 = normal.
Exclusion zone excl on/off on Adds the strong mask to the exclusion mask, so the main edges are protected for sure.
Edge processing edgeproc 0 – 10 0 Adds part of the edge mask itself to the processed area; high values start to eat into the lines.
Show mask showmask none, outside mask, shrink mask, edge mask, strong mask none Shows a mask instead of the result, for tuning.
Tools: Expr tools akarin, cranexpr, std akarin (std without AVX2) Expression evaluator.
Tools: Limiter tools vszip, std vszip Clamps the masks of float clips.
Tools: EdgeMasks tools edgemasks, std edgemasks Prewitt edge mask implementation.
Tools: RG tools zsmooth, neo_smo zsmooth Repair implementation; only used with contrast sharpening.
Tools: Median tools zsmooth zsmooth Median implementation; only used with contrast sharpening.

Example

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

# applying FineDeHalo to remove halos
clip = dehalo.FineDehalo(clip, tools={'expr': 'akarin', 'rg': 'zsmooth', 'median': 'zsmooth', 'limiter': 'vszip', 'edgemasks': 'edgemasks'})

How Hybrid calls it

  • FineDeHalo works on YUV and Gray clips, integer and float; RGB is converted first.
  • Values are only written when they differ from the defaults. Radius y is written whenever it differs from radius x, because the script uses rx for ry when ry is left out.
  • The GUI keeps each minimum threshold below its maximum; equal values would make the script divide by zero, and a reversed pair would invert the mask.
  • Thresholds are entered on the 8-bit scale; the script scales them to the clip's bit depth.
  • DeHalo_alpha runs with fixed sampling 1.5 and sensitivities 50/50.
  • FineDeHalo also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

The script

FineDeHalo is a port of Didée's AviSynth FineDehalo, taken over from havsfunc. The script also accepts a custom edge mask, which Hybrid does not offer.

Sources