A1.1.8
Describe the concept of compression
Compression decreases disk space needed for files and bandwidth for transfer → more efficient use of resources.
Lossless vs Lossy Compression
Lossless Compression
- Identifies redundant patterns and eliminates them without losing essential information.
- Decompressed (解压缩, 从压缩状态恢复到原文件状态) file is an exact replica of the original — preserves integrity and quality.
- Process is reversible.
- Compression ratio generally smaller than lossy.
Lossy Compression
- More aggressive strategy for higher compression ratios.
- Deliberately discards data — typically minor details less noticeable to human eye/ear (perceptual redundancy).
- Significantly smaller file sizes → suitable for audio, video, images.
- Discarded info can compromise (危及, 损害) quality of reconstructed file → process is irreversible.
Differences
| Feature | Lossless | Lossy |
|---|---|---|
| Data Integrity | Preserves all original data; decompressed = original | Introduces variations; some data deliberately discarded |
| Compression Ratio | Lower (no data removed) | Higher (less important data removed) |
| Applications | Where integrity is critical: backups, archives, document editing | Audio/video/images where slight quality loss is acceptable |
| Perceptual Redundancy | Not exploited | Exploited — discards what humans won’t notice |
| Reversible? | Reversible — perfectly reconstructed | Irreversible — discarded data cannot be restored |
Run-length encoding, Transform coding
- Run-length encoding (RLE) — simple, efficient lossless technique for data with repetitive patterns. Replaces consecutive occurrences of the same value with a single code representing the run length. E.g.,
AAAAA→5A. - Transform coding — advanced lossy technique. Uses mathematical transformations (like DCT, Discrete Cosine Transform) to convert data into a form where structure/redundancy are easier to identify → much higher compression ratios.
- Lossy: compressed file cannot be perfectly reconstructed; irreversible — data deliberately discarded permanently.
Widely used in:
- JPEG: transforms images into frequency domain before quantizing (量化).
- MP3: transforms audio into frequency domain before encoding (编码).
| Compression Type | Examples | Typical Applications |
|---|---|---|
| Lossless | GIF, TIFF, PNG, PDF, ZIP | Backups, archives, text files, simple graphics |
| Lossy | JPEG, MP3, MP4 | Images, audio, video where small quality loss is OK |
| Technique (Lossless) | Run-Length Encoding (RLE) | Fax images (传真), simple graphics, text |
| Technique (Lossy) | Transform Coding (JPEG, MP3, MP4) | Image, audio, video compression |