How CDEF Improves Visual Quality in AVIF Images
The Constrained Directional Enhancement Filter (CDEF) is a core in-loop filtering technology used in the AVIF image format, inherited from the AV1 video codec. It significantly enhances visual fidelity by targeting and eliminating ringing artifacts and compression noise along high-contrast boundaries without blurring the underlying picture. By analyzing edge directions and applying adaptive, non-linear smoothing parallel to those edges, CDEF ensures that AVIF files retain sharp lines, clean text, and natural textures even at aggressive compression levels.
The Problem CDEF Solves: Ringing Artifacts
Block-based transform coding, which forms the foundation of formats like AVIF, naturally introduces high-frequency noise known as ringing artifacts (or the Gibbs phenomenon). When an image contains strong contrast—such as dark text on a bright background or hard architectural silhouettes—the quantization process discards fine frequency components. This results in visible ripples, halos, or speckled noise around sharp contours. While traditional deblocking filters smooth the seams between block boundaries, they cannot address ringing artifacts situated inside the blocks.
Step 1: Direction Estimation
To address these artifacts without destroying fine details, CDEF first performs a directional search. The encoder divides the image into small blocks (typically 8x8 pixels) and analyzes the gradient vectors to determine the dominant direction of any edges present in that area. It selects one of eight possible directions (ranging from 0 to 157.5 degrees). If an area lacks a distinct edge or is flat, the filter identifies this state to avoid applying directional bias.
Step 2: Adaptive Non-Linear Filtering
Once the dominant direction is established, CDEF applies a non-linear spatial filter tailored to that specific angle:
- Primary Filter Taps: The filter applies taps along the detected direction of the edge. Because the smoothing occurs parallel to the edge rather than across it, the sharpness of the boundary is fully preserved while noise along the edge is flattened.
- Secondary Filter Taps: To capture residual noise, secondary taps are applied at an angle to the primary direction. These taps use much lower weights to prevent blurring across the contour.
- Threshold Clamping (The "Constrained" Mechanism): Unlike traditional linear filters, CDEF uses a mathematical threshold (damping) that limits how much a pixel's value can shift relative to its neighbors. If a neighboring pixel differs significantly in luminance or color, the filter ignores it. This constraint ensures that real image features and fine textures are not mistaken for compression noise and accidentally smoothed away.
Placement in the AVIF Pipeline
CDEF operates as an in-loop filter, meaning it processes the image data directly inside the decoding pipeline:
- Deblocking Filter: Smooths the grid-like block boundaries.
- CDEF: Cleans up ringing and preserves edge directionality.
- Loop Restoration: Restores fine textures using Wiener or self-guided filters.
By running immediately after the deblocking stage, CDEF provides clean, noise-free edges for the subsequent restoration step, preventing later algorithms from amplifying compression errors.
Direct Impact on User Experience
By actively reconstructing edge integrity, CDEF allows AVIF to excel where older formats like JPEG struggle:
- Legibility: Small typography and graphical user interface elements remain crisp without the halo artifacts that typically degrade readability.
- Efficiency: Because CDEF cleans up high-frequency errors effectively, encoders can quantize images more heavily, yielding file size reductions of 30% to 50% compared to JPEG and WebP while maintaining perceived sharpness.
- Clean Illustrations and Vector Art: Visual assets with flat colors and sharp divides stay pristine, making AVIF highly versatile for photographic and non-photographic web content alike.