📸 Section 1: Introduction & Color Reduction
JPEG is a Lossy Compression Standard
It achieves small file sizes by exploiting the limitations of the Human Visual System to discard data we are least likely to notice.
Stage 1: Separate & Subsample (Color Reduction)
- Conversion: Image data moves from RGB (display colors) to YCbCr.
- Y (Luminance): Brightness (the highly sensitive channel).
- Cb/Cr (Chrominance): Color (the less sensitive channels).
- Lossy Trick: Chroma Subsampling is performed. Color data is averaged across pixel groups (e.g., a 2 × 2 block) and discarded.
- Result: Instantly reduces the total amount of data to be processed.
🧠 Section 2: Block & Transform (Frequency Analysis)
Stage 2: Block, Transform, and Analyze (The DCT)
- Blocking: The image is divided into small, independent 8 × 8 pixel blocks.
- The Transform: The Discrete Cosine Transform (DCT) is applied to each block. The DCT changes the representation of the data, converting pixel intensity into patterns.
- Frequency Concept: The DCT yields 64 coefficients:
- Top-Left: Represents smooth, overall tone (Low-Frequency, Most Important).
- Bottom-Right: Represents fine detail, sharp edges, or noise (High-Frequency, Least Important).
🗑️ Section 3: Quantization (Permanent Data Loss)
Stage 3: Throwing Away Information (Quantization)
- Primary Lossy Step: This is the irreversible step controlled by the JPEG quality slider.
- Process: A Quantization Table is used to divide the DCT coefficients.
- Goal: Since high-frequency coefficients (bottom-right) are small and least noticeable to the eye, this division and subsequent rounding causes many of them to turn into zero.
- Impact: This is the major data reduction step. The permanent loss of high-frequency detail can cause visible artifacts (like blockiness) at high compression levels.
📦 Section 4: Final Packaging (Lossless Coding)
Stage 4: Lossless Packing (Entropy Coding)
- Zig-Zag Ordering: The remaining coefficients are read out in a **zig-zag pattern** to group the large runs of zeros together.
- Encoding: Two lossless compression techniques are used to finalize the file without losing any more information:
- Run-Length Encoding (RLE): Replaces strings of zeros with a simple count (e.g., "6 zeros").
- Huffman Coding: Assigns the most frequent numbers (especially zeros) shorter binary codes.
- Result: The data is packed into the smallest possible compressed
.jpg file.