Vapoursynth pSharpen

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

pSharpen is a "two-point" sharpener similar to LimitedSharpenFaster: it pushes each pixel towards the nearer local extreme, so it produces no halos.

Filtering → Vapoursynth → Sharpen

pSharpen controls in Hybrid
pSharpen controls in Hybrid

What it does

For each luma pixel the darkest and brightest value in the 3×3 neighborhood are taken, and the pixel is moved towards the one that is closer. Values are only redistributed inside the local minimum/maximum range, so nothing overshoots. Optional supersampling reduces jagged diagonal edges. Only luma is sharpened; chroma is copied.

Settings

Control Parameter Range / values Hybrid default Meaning
Strength strength 0 – 100 25 How strongly pixels are pushed towards the local extreme (percent); 0 = no sharpening.
Threshold threshold 0 – 100 75 How much of the local contrast range is treated as edge; 0 = no change, higher values sharpen more.
Super sampling x / y ss_x / ss_y 1 – 100 1 / 1 Enlargement factors before sharpening (Lanczos, size rounded to mod 4); the picture is scaled back afterwards. 1 = off.
Tools: Expr – akarin, cranexpr, std akarin (std without AVX2) Expression plugin.

Example

Default settings on a 10-bit YUV 4:2:0 source (640x356):

# sharpening using PSharpen
clip = sharpen.psharpen(clip, tools={'expr': 'akarin'})

How Hybrid calls it

  • pSharpen works on integer YUV clips with 8, 10, 12 or 16 bit; other formats are converted first.
  • Values are only written when they differ from 25 / 75 / 1 / 1, the script's own defaults.
  • Strength and Threshold are percentages; the script maps the pixel values to an 8-bit equivalent internally, so the result does not depend on the bit depth.
  • Supersampling costs grow with the area: 2 × 2 means four times the work. With supersampling chroma also goes through the Lanczos round trip, although it is not sharpened.
  • The output keeps the input size.
  • pSharpen also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

Origin

pSharpen comes from an AviSynth script function posted on Doom9. A VapourSynth version was part of havsfunc earlier; the current havsfunc no longer contains it, Hybrid keeps its own copy in the script collection.

Sources