Set Minkowski Norm and Sigma in FFmpeg Colorconstancy
The FFmpeg colorconstancy filter applies computational
color constancy algorithms to automatically detect and correct the color
cast (illuminant) in a video. By configuring the Minkowski norm and
Gaussian sigma values, you can switch between classic color constancy
frameworks—such as Grey-World, Max-RGB, and higher-order Gray-Edge
methods—to fine-tune how illumination is estimated.
Understanding the Parameters
The colorconstancy filter utilizes two primary
parameters to shape how pixels and color gradients are weighted during
illuminant estimation:
minkowski(orm): Specifies the order \(p\) of the Minkowski norm.0: Represents the \(\infty\)-norm (\(L_\infty\)), which calculates the maximum values (equivalent to the Max-RGB algorithm).1: Represents the standard sum/average (\(L_1\)), which assumes the average scene reflectance is neutral (equivalent to the Grey-World algorithm).> 1(typically4to11): Gives higher weights to stronger pixel values or edge gradients, commonly used in Gray-Edge methods.
sigma(ors): Defines the standard deviation of the Gaussian filter applied to the image before computing derivatives or color averages. A non-zero value smooths out high-frequency noise that could otherwise distort the illuminant estimation.
These parameters are frequently paired with difford
(derivative order), where 0 applies to raw pixel colors,
and 1 or 2 applies to spatial derivatives
(edges).
Configuration Syntax
To set the Minkowski norm and sigma, pass them as key-value pairs
inside the -vf (video filter) option:
ffmpeg -i input.mp4 -vf "colorconstancy=minkowski=VALUE:sigma=VALUE" output.mp4You can also use the short aliases m and
s:
ffmpeg -i input.mp4 -vf "colorconstancy=m=VALUE:s=VALUE" output.mp4Practical Examples
1. Gray-Edge (First-Order Derivative)
For scenes with mixed lighting or prominent textures, the first-order
Gray-Edge framework often produces the most natural white balance. It
typically utilizes a Gaussian smoothing filter (sigma) of 1
or 2 and a Minkowski norm (minkowski) between 5 and 10:
ffmpeg -i input.mp4 -vf "colorconstancy=difford=1:minkowski=6:sigma=1.5" -c:a copy output.mp42. Max-RGB with Noise Suppression
To run a Max-RGB estimation while using a slight Gaussian blur to prevent isolated bright noise pixels from skewing the results:
ffmpeg -i input.mp4 -vf "colorconstancy=difford=0:minkowski=0:sigma=1" -c:a copy output.mp43. Smoothed Grey-World
To run standard Grey-World color constancy with spatial smoothing to reduce sensor noise impact:
ffmpeg -i input.mp4 -vf "colorconstancy=difford=0:minkowski=1:sigma=2" -c:a copy output.mp4