How CDEF Reduces Ringing Artifacts in AVIF

The Constrained Directional Enhancement Filter (CDEF) is an in-loop filtering tool in the AV1 video codec and AVIF image format designed to eliminate ringing artifacts and mosquito noise near sharp edges. By determining the primary direction of edges within small pixel blocks and applying a non-linear low-pass filter aligned with those directions, CDEF effectively smooths out high-frequency distortion without blurring fine details or structural boundaries.

The Origin of Ringing Artifacts

In lossy image compression like AVIF, an image is divided into blocks and transformed into frequency components via discrete cosine transforms (DCT) or asymmetric discrete sine transforms (ADST). When an image contains high-contrast transitions—such as black text on a white background or the crisp outline of an object—the quantization step discards high-frequency coefficients to save data. This loss causes the Gibbs phenomenon, manifesting as rippling distortions or "halos" along the boundaries, commonly known as ringing artifacts.

CDEF addresses ringing by first identifying the structural orientation of the image content. The image is processed in small blocks (typically 8x8 pixels). For each block, the algorithm computes variance along eight possible directions (spanning 0 to 180 degrees).

The direction that yields the lowest variance along its path is selected as the dominant edge direction. By identifying which way the edge runs, the algorithm ensures that subsequent filtering respects the visual geometry of the scene rather than treating the block uniformly.

Directional Filtering Along the Edge

Once the primary direction is established, CDEF applies a non-linear low-pass filter. Standard deblocking or smoothing filters often filter across edges, which blurs the boundary and degrades image sharpness. In contrast, CDEF filters primarily along the detected edge direction.

The filter uses a combination of primary and secondary taps:

Non-Linear Clamping and Constraints

The critical mechanism preventing CDEF from destroying true image detail is its constraint mechanism. A standard linear filter averages neighboring pixels, which can erode subtle textures. CDEF prevents this by imposing a non-linear threshold (clamping) on how much any given pixel value can change.

Each pixel difference is evaluated against two parameters:

If a neighboring pixel’s intensity differs significantly from the pixel being filtered—such as the opposite side of a high-contrast boundary—its contribution is clamped to zero or heavily attenuated. Consequently, low-amplitude ringing ripples fall within the threshold and are flattened, while the high-contrast transition remains intact.

Efficiency and Visual Impact

Because CDEF merges the concepts of directional filtering (from the Daala codec) and constrained low-pass filtering (from the Thor codec), it executes in a single filtering pass. In AVIF images, this allows sharp graphical elements, typography, and high-contrast photographic edges to remain visually crisp at low file sizes where traditional JPEG compression produces noticeable distortion.