Vapoursynth CLAHE

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

CLAHE (Contrast Limited Adaptive Histogram Equalization) raises the local contrast, which helps with flat, hazy or washed-out pictures. Hybrid uses the CLAHE filter of the vszip plugin.

Filtering → Vapoursynth → Color → Auto

CLAHE controls in Hybrid
CLAHE controls in Hybrid

What it does

The frame is split into a grid of tiles, and the histogram of each tile is equalized, so dark and bright areas each use the full range locally. A contrast limit caps the equalization, so that noise in flat areas is not boosted too much. More tiles give more local and less global contrast.

Settings

Control Parameter Range Hybrid default Meaning
luma only – on/off on Process only the luma plane and keep the original chroma, so hue and saturation stay untouched. When off, U and V are equalized too, which shifts the colors noticeably.
Limit limit 0 – 255 7 Contrast limit on the 8-bit scale; 0 switches the effect off, above about 40 it hardly changes any more.
Tile (x/y) tiles 1 – 64 each 3 / 3 Number of tiles horizontally and vertically; limited to the size of the filtered plane.


Example

Default settings (luma only) on a 10-bit YUV 4:2:0 source:

# adjusting local contrast using CLAHE (luma only)
clipCLAHE = core.std.ShufflePlanes(clips=[clip], planes=[0], colorfamily=vs.GRAY)
clipCLAHE = core.vszip.CLAHE(clipCLAHE, limit=28, tiles=3)
clip = core.std.ShufflePlanes(clips=[clipCLAHE, clip, clip], planes=[0, 1, 2], colorfamily=vs.YUV)

How Hybrid calls it

  • CLAHE works on YUV and gray clips, integer 8–16 bit and float; RGB clips are converted to YUV 4:4:4 first.
  • The plugin needs at least one pixel per tile, so Hybrid limits the tile count per axis to the width and height of the smallest filtered plane (the chroma planes for subsampled YUV, the luma plane in luma-only mode).
  • Limit is scaled to the clip's bit depth (×4 at 10 bit, ×16 at 12 bit, ×256 at 16 bit and float), so the same value has the same effect at every bit depth.
  • Tile is written as one number when both values are equal, otherwise as a pair.
  • With luma only Hybrid takes out the luma plane, runs CLAHE on it and puts the original chroma back.
  • CLAHE also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

vszip (CLAHE)

vszip is a collection of filters written in Zig. Its CLAHE follows OpenCV's algorithm: CLAHE(clip, limit=7, tiles=3). The documentation notes that at 16 bit the limit has to be multiplied by 256 to match the 8-bit result — Hybrid does that scaling itself. The plugin has no planes parameter, which is why Hybrid splits off the luma plane for luma only.

Sources