Configure FFmpeg Colorconstancy Minkowski and Sigma

This article provides a direct guide on how to configure the Minkowski norm and sigma parameters in the FFmpeg colorconstancy filter. You will learn the exact syntax, parameter ranges, and how adjustments to these values affect color correction and illumination estimation in your videos.

Understanding the Parameters

The colorconstancy filter in FFmpeg is used to estimate and correct the scene illumination of a video, ensuring that colors appear natural regardless of the light source. It relies on two primary configuration parameters to tune the color correction algorithm:

  • Minkowski Norm (minkowski or m): This parameter defines the norm used in the color constancy calculation. It determines how pixel values are weighted.
    • Range: An integer from 0 to 20.
    • Default: 1
    • Behavior: A value of 0 represents the infinite norm (Max-RGB algorithm), which estimates illumination based on the brightest pixels in the image. Values of 1 (Grey-World) or higher (Grey-Edge) place different emphasis on the distribution of colors and edges. Higher values bias the algorithm toward more prominent color variations.
  • Sigma (sigma or s): This parameter sets the standard deviation of the Gaussian blur applied to the image before calculating derivatives (edges).
    • Range: A float from 0.0 to 1024.0.
    • Default: 1.0
    • Behavior: Setting sigma to 0.0 disables Gaussian smoothing entirely. Higher values apply more smoothing, which helps reduce high-frequency noise and prevents compression artifacts from interfering with the color estimation. However, excessively high values can blur important edge details required for the algorithm.

Syntax and Configuration

To use the colorconstancy filter, you must pass the parameters using the ffmpeg video filter (-vf) flag. The parameters can be defined using their full names or short aliases.

The basic syntax is as follows:

ffmpeg -i input.mp4 -vf "colorconstancy=minkowski=VALUE:sigma=VALUE" output.mp4

Alternatively, you can use the short aliases m and s:

ffmpeg -i input.mp4 -vf "colorconstancy=m=VALUE:s=VALUE" output.mp4

Practical Configuration Examples

Below are practical configurations depending on your processing needs:

1. Standard Grey-World (Default)

To use the default configuration (Minkowski norm of 1 and sigma of 1.0):

ffmpeg -i input.mp4 -vf "colorconstancy=minkowski=1:sigma=1.0" output.mp4

2. Max-RGB Algorithm (Brightest Pixels)

To bias the algorithm toward the brightest highlights in the frame, set the Minkowski norm to 0 and disable smoothing by setting sigma to 0:

ffmpeg -i input.mp4 -vf "colorconstancy=m=0:s=0" output.mp4

3. Noise-Resistant Grey-Edge Algorithm

For videos with significant sensor noise, increase the sigma value to smooth out noise before estimating color, and use a higher Minkowski norm (e.g., 3 or 4) to focus on major edge transitions:

ffmpeg -i input.mp4 -vf "colorconstancy=m=3:s=2.5" output.mp4