AI summary by TwinMind
How are Images Compressed? [46MB ↘↘ 4.07MB] JPEG In Depth
Branch Education
18m 47s
Introduction & JPEG Importance
- Uncompressed image: 46 megabytes vs compressed JPEG: 4.1 megabytes
- JPEG compresses images to 1/10th size while maintaining resolution and high quality
- 86% of internet images are JPEGs (based on research)
- Algorithm used everywhere in digital photography
- Video compression (H.264) builds on JPEG principles
Human Eye Limitations Exploited by JPEG
- Two types of light receptive cells: rods and cones
- 100 million rod cells (brightness/darkness sensitive)
- 6 million cone cells (color sensitive with red, green, blue receptors)
- Eyes more receptive to luminance (brightness) than chrominance (color)
- Tulip image example: black/white version appears as detailed as color version
- Color-only version appears significantly less detailed
Five Key JPEG Compression Steps
Step 1: Color Space Conversion
- Original pixels: RGB values (0-255 each)
- Converts RGB to YCbCr (luminance, blue chrominance, red chrominance)
- Process is reversible with no data loss
Step 2: Chrominance Down Sampling
- Divides blue and red chrominance into 2x2 pixel blocks
- Calculates average value for each block
- Shrinks chrominance images to 1/4 original size
- Luminance remains full size
- Overall image becomes half original size
- When reassembling: chrominance rescaled to match luminance size
Step 3: Discrete Cosine Transform (DCT)
- Divides image into 8x8 blocks (64 pixels each)
- Shifts pixel values by subtracting 128 (range becomes -128 to 127)
- Uses 64 base images as "paint colors"
- Transforms 64 pixel values into 64 constants representing base image usage
- Like recreating painting with specific amounts of different paints
- No compression occurs in this step
Step 4: Quantization
- Divides DCT constants by quantization table values
- Rounds results to nearest integers
- Quantization table: higher numbers in bottom right (high frequency), smaller in top left (distinct patterns)
- Creates many zeros by removing high-frequency data eyes can't perceive
- Separate quantization tables for luminance and chrominance
- This step removes data but only what eyes don't notice
Step 5: Run Length and Huffman Encoding
- Lists values using zigzag pattern (non-zero numbers likely in upper area)
- Run length encoding: lists numbers and counts of zeros instead of listing all zeros
- Huffman encoding: separate compression algorithm for final optimization
- Compresses 64 pixel values into couple dozen numbers
H.264 Video Compression Connection
- Uses chrominance down sampling and DCT/quantization variations
- More complex: compresses 24-60+ frames per second
- Uses I-frames (similar to JPEG) for 1 in 30 frames
- Other 29 frames use prediction/bi-directional prediction
- Codes only differences and motion using previous frames as reference
- I-frame frequency varies, typically at scene changes
Image Reconstruction Process
- Reverse steps: disassemble run length encoding and Huffman decoding
- Multiply values by quantization table
- Multiply constants by base images and add together
- Upscale chrominance images
- Convert luminance/chrominance back to RGB
- 4 luminance blocks + 2 chrominance sets = 16x16 pixel grid
Performance Example
- 4032x3024 pixel image = 190,512 blocks
- Every block processed through all algorithm steps
- Smartphones perform compression/decompression faster than finger swipe
JPEG Limitations and Notes
- Compression level adjustable via quantization table values
- Higher table values = more zeros = smaller files but more artifacts
- Artifacts appear as blurry splotches on square block edges
- Quantization reduces precision more for high-frequency vs low-frequency data
- Excellent for natural photography (smooth textures, camera focus imperfections)
- Poor for vector graphics (creates noticeable artifacts at boundary lines)
- Straight lines difficult to reconstruct with base images when compressed
- Most common format: old, well-understood, royalty-free
- Other formats available with better compression capabilities
