What Are the 63 AC Coefficients in JPEG DCT?
In JPEG image compression, an image is divided into 8x8 pixel blocks and converted into frequency space using the Discrete Cosine Transform (DCT), resulting in 64 frequency coefficients per block. While the single Direct Current (DC) coefficient represents the average color or brightness across the block, the remaining 63 Alternating Current (AC) coefficients represent the specific spatial frequencies, textures, edges, and directional patterns within that block. This article explains what these 63 AC coefficients capture, how they are structured across the 8x8 matrix, and why they are central to the JPEG compression process.
Spatial Frequencies and Gradients
Each of the 63 AC coefficients corresponds to a specific basic cosine wave pattern running at different frequencies across the 8x8 grid:
- Horizontal Frequency (Moving Right): As you move horizontally across the top row from the DC coefficient, the AC coefficients represent increasingly rapid changes in color or brightness from left to right. High values here signify vertical edges or fine vertical stripes.
- Vertical Frequency (Moving Down): As you move vertically down the first column from the DC coefficient, the coefficients capture increasingly rapid changes from top to bottom. High values here signify horizontal edges or fine horizontal stripes.
- Diagonal Frequency (Moving Diagonally): The remaining coefficients represent combinations of horizontal and vertical variations. The bottom-right corner represents the highest diagonal spatial frequency—alternating checkered patterns that switch values almost every pixel.
Low vs. High Frequencies
The position of an AC coefficient dictates the scale of the visual feature it describes:
- Low-Frequency AC Coefficients: Clustered near the top-left (adjacent to the DC coefficient), these values represent broad variations, smooth shading, soft gradients, and the general contours of objects. Because the human eye is extremely sensitive to these gradual transitions, retaining accurate values for these coefficients is critical for perceived image quality.
- High-Frequency AC Coefficients: Located toward the bottom-right of the matrix, these values capture fine details, sharp boundaries, noise, and complex surface textures. The human visual system is significantly less sensitive to subtle errors at these rapid frequencies.
Role in Quantization and Compression
The purpose of isolating the 63 AC coefficients by frequency is to make compression possible through quantization:
- Quantization: JPEG applies a quantization matrix that divides the high-frequency AC coefficients by larger step sizes than the low-frequency ones. This deliberately rounds many high-frequency coefficients down to zero.
- Zig-Zag Scanning: After quantization, the 64 coefficients are read in a zig-zag order, starting at the DC coefficient and traversing from lowest to highest frequency AC coefficients.
- Entropy Encoding: Because the high-frequency AC values are frequently rounded to zero, the zig-zag sequence produces long runs of trailing zeros. These sequences are then compressed using run-length encoding and Huffman coding, drastically reducing file size while preserving the visually essential components of the image.