What Is the End-of-Block Marker in JPEG Encoding?
This article explains the purpose and function of the End-of-Block (EOB) marker within JPEG entropy encoding. It covers how an image block is transformed and ordered, why the EOB marker is necessary, and how it drastically optimizes file compression by signaling the termination of non-zero frequency data.
The Context: Transform, Quantization, and the Zig-Zag Scan
To understand the EOB marker, it is necessary to look at how a standard JPEG processes image data:
- Discrete Cosine Transform (DCT): The image is divided into 8×8 pixel blocks. The DCT converts spatial pixel data into 64 frequency coefficients: one DC coefficient (the average block brightness) and 63 AC coefficients (representing details from low to high frequencies).
- Quantization: The coefficients are divided by values in a quantization matrix and rounded to integers. Because human vision is less sensitive to high-frequency details, high-frequency coefficients are heavily quantized and often become zero.
- Zig-Zag Ordering: The 8×8 matrix is reordered linearly using a zig-zag pattern. This places the low-frequency coefficients first and groups the long runs of zero-value high-frequency coefficients toward the end of the sequence.
What the End-of-Block (EOB) Marker Signifies
The End-of-Block (EOB) marker is a special symbol used during the entropy encoding phase (typically Huffman coding) to indicate that all remaining AC coefficients in the current 8×8 block are zero.
Instead of writing out repeated run-length codes for every remaining zero up to the 64th coefficient, the encoder emits a single EOB code word immediately following the last non-zero coefficient.
How the EOB Marker Works in Practice
During run-length encoding (RLE), non-zero coefficients are encoded
as a pair: (run of preceding zeros, coefficient value).
- If a quantized 8×8 block contains non-zero data only up to the 15th coefficient in the zig-zag sequence, coefficients 16 through 63 are all zero.
- Without an EOB marker, the encoder would have to explicitly code the remaining 48 zeros using multiple zero-run symbols.
- With the EOB marker, the encoder outputs the EOB code directly after the 15th coefficient.
- When the decoder encounters the EOB code, it automatically populates all remaining positions up to the 64th coefficient with zeros and immediately begins parsing the DC coefficient of the next 8×8 block.
Significance to Compression Efficiency
The EOB marker is critical to JPEG compression efficiency:
- Bit Savings: High-frequency details in natural images are predominantly zero after quantization. A single short Huffman code (often only 2 to 4 bits) replaces dozens of individual zero representations.
- Block Synchronization: It provides an unambiguous stopping point for AC decoding within an individual block, preventing the decoder from misinterpreting subsequent bits meant for the next block.