Vapoursynth Grayworld

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

Grayworld is an automatic white balance (color constancy) filter. It assumes that the average color of a scene is neutral gray and removes the color cast it measures in each frame.

Filtering → Vapoursynth → Color → Auto

Grayworld controls in Hybrid
Grayworld controls in Hybrid

What it does

For each frame the filter measures the average color and shifts the colors so that this average becomes gray. It works on every frame separately and has no strength setting. It suits footage with an overall tint, for example a wrong white balance or a faded color cast; scenes that really are dominated by one color (a blue sky, a green lawn) get neutralized as well.

Settings

Control Parameter Values Hybrid default Meaning
CC Mode cc mean, median mean How the average color is measured; median is not affected by extreme luma or chroma values.

Example

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

# adjusting color space from YUV420P10 to RGBS for vsGrayworld
clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s="470bg", range_in_s="limited", range_s="full")
# adjusting color using Grayworld
# convert to linear color space
grayworldTransfer = clip.get_frame(0).props.get('_Transfer', vs.TRANSFER_BT709)
if grayworldTransfer in (vs.TRANSFER_UNSPECIFIED, vs.TRANSFER_LINEAR):
  grayworldTransfer = vs.TRANSFER_BT709
clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, transfer_in=grayworldTransfer, transfer_s="linear")
# making sure 0-1 limits are respected
clip = core.vszip.Limiter(clip=clip, min=[0,0,0], max=[1,1,1])
clip = core.grwrld.grayworld(clip)
# undo conversion to linear color space
clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, transfer_in_s="linear", transfer=grayworldTransfer)
# adjusting output color from RGBS to YUV420P10 for NVEncModel
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, matrix_s="470bg", range_in_s="full", range_s="limited", dither_type="error_diffusion")

How Hybrid calls it

  • The filter works on 32-bit float RGB: Hybrid converts the clip to RGBS before it and back afterwards.
  • The plugin expects linear light. Hybrid reads the clip's transfer characteristic from its _Transfer frame property (BT.709 if unknown), converts to linear light before the filter, clamps the values to 0–1 and converts back afterwards.
  • CC Mode is only written when it is not mean.
  • Grayworld also offers the common options (Masked, ApplyOnlyTo, Merge, OnRegion, Gimmick).

Background

grayworld (plugin)

The plugin by Asd-g is a port of FFmpeg's grayworld filter for VapourSynth and AviSynth+. It expects planar 32-bit float RGB in linear light. Parameters: cc (0 = mean, 1 = median) and opt (CPU optimization, automatic by default; not exposed in Hybrid).

AviSynth

The same plugin is available for AviSynth+. ColorYUV's autowhite is a simpler per-frame cast removal.

Sources