AP® Computer Science Principles · Big Idea 2 · Topic 2.2
Lossy Compression
Lossy compression shrinks a file by permanently discarding the details human senses are least likely to notice, so it looks or sounds almost the same but takes up far less space.
Your eyes and ears are not equally sensitive to everything. You notice big changes in brightness much more than tiny shifts in color, and you hear mid-range tones much better than extremely high or low frequencies. Lossy compression exploits this gap. It does not treat every bit of data as equally important. Instead it uses a model of human perception to find the data you would never miss, and throws that away first, keeping file size down while keeping the result looking or sounding right to you.
For images, a lossy algorithm often groups nearby pixels and simplifies small color variations within each group, since your eye blends subtle color differences together anyway, while it preserves sharp brightness changes, since your eye is very sensitive to edges and contrast. For sound, the algorithm analyzes which frequencies are present and removes ones outside typical human hearing range, or ones masked by louder nearby sounds you would not notice anyway. In both cases the deleted data is gone permanently. You cannot recover the original file from the compressed one.
This connects directly to how data gets represented as bits in the first place: compression only works because images and sound are already stored as numbers that can be approximated or rounded. It also sets up a tradeoff that runs through the rest of the unit, between file size and fidelity. Compress once lightly and the loss is invisible. Compress repeatedly or too aggressively and the damage compounds, visible as blurry blocks in images or tinny, hollow audio.
Key terms
- Lossy compression
- A method of shrinking file size by permanently removing data judged least noticeable to human senses.
- Lossless compression
- A method of shrinking file size that preserves every original bit so the file can be perfectly restored.
- Perceptual model
- A model of what details human vision or hearing can and cannot detect, used to decide what to discard.
- Generation loss
- The accumulating quality damage that results from compressing and saving a lossy file multiple times in a row.
Watch it explained
- How it worksHow does a lossy image algorithm choose which details your eye will never miss?
- How it worksWalk me through what leaves a sound file when the frequencies you cannot hear are deleted.
- Worked exampleShow me one image saved at high quality and the same image saved at heavy compression.
- Common mistakeWhy doesn't a lossy algorithm delete data at random instead of choosing exactly what your eye won't miss?
- Going furtherWhat happens to a picture compressed lossily, saved, and compressed again ten times over?
Check yourself
End of topic.